Why should automation never use long-lived access keys in CI?
IntermediateConceptboto3 & AWS automation
Answer
Static keys leak through logs, forks, laptops and old pipelines, never expire, and are hard to attribute. Instead:
- GitHub Actions/GitLab: OIDC federation to an IAM role (
aws-actions/configure-aws-credentialswithrole-to-assume), with the trust policy restricted to a repo and branch. - EC2: instance profiles. EKS: IRSA or Pod Identity. ECS: task roles. Lambda: execution role.
- Humans: IAM Identity Center (SSO) with
aws sso login.
boto3 picks all of these up through the default chain without code changes.
More on boto3 & AWS automation
What is the difference between a boto3 Session, client and resource?BeginnerHow does boto3 find credentials?BeginnerHow does boto3 decide the region, and what is the gotcha with `AWS_REGION`?AdvancedWhy do you need paginators, and how do you use them?BeginnerWhat is JMESPath `search()` on paginators?AdvancedHow do you handle errors from boto3?Beginner