How do you authenticate GitLab CI to AWS without storing keys?

AdvancedScenarioGitLab CI
Answer

Situation read → OIDC federation.

What I'd do →

  1. Declare id_tokens: { AWS_TOKEN: { aud: https://gitlab.example.com } } in the job.
  2. Create an IAM OIDC provider for the GitLab issuer and a role whose trust policy matches sub like project_path:group/app:ref_type:branch:ref:main.
  3. In the script: aws sts assume-role-with-web-identity --role-arn $ROLE --role-session-name ci --web-identity-token "$AWS_TOKEN".

Why → Tokens are short-lived and identity-bound.

Interview tip → Same pattern as GitHub Actions OIDC.

All CI/CD questions Roadmap: GitLab CI/CD

More on GitLab CI