Error: Error querying AMI: NoCredentialProviders (Packer amazon-ebs)
Fixes Packer failing to find AWS credentials when querying AMIs. For engineers whose builds fail at AMI lookup with NoCredentialProviders, covering the credential chain.
Error: Error querying AMI: NoCredentialProviders: no valid providers in chain (Packer)
TL;DR
Packer found no AWS credentials in any source. Provide them via environment variables, a profile, or -var flags for aws_access_key/aws_secret_key, then rebuild.
The error
==> amazonebs: Prevalidating AMI Name...
==> amazonebs: Error querying AMI: NoCredentialProviders: no valid providers in chain
==> amazonebs: caused by: EnvAccessKeyNotFound: failed to find credentials in the environment.
==> amazonebs: SharedCredsLoad: failed to load profile, .
==> amazonebs: EC2RoleRequestError: no EC2 instance role foundFix it
- Check the environment Packer runs in:
aws sts get-caller-identity.
- Success check: it works. If not, the problem is AWS auth, not Packer.
- Provide credentials one of these ways: export
AWS_ACCESS_KEY_ID/AWS_SECRET_ACCESS_KEY, setaws_profilein the template, or pass `-var 'awsaccesskey [your value] -var 'awssecretkey [your value]
- Success check:
packer buildgets past AMI querying.
- On EC2 build hosts, attach an instance profile with AMI permissions instead of static keys.
- Success check: no credentials in the environment, yet the build works.
- Re-run
packer build.
- Success check:
Prevalidating AMI Namesucceeds and the build proceeds.
When to use this
You hit this at the start of an amazon-ebs build, before any instance launches.
When NOT to use this
Do not use this for SSH failures later in the build or for UnauthorizedOperation on specific APIs. This is specifically the empty credential chain.
Compatibility
Packer 1.x, amazon builders. The chain matches the AWS SDK.
Variants
EnvAccessKeyNotFound,SharedCredsLoad: failed to load profile,EC2RoleRequestErroras thecaused bylines- The same failure on
amazon-instance,amazon-ebssurrogate, and other EC2 builders
Root cause
The AWS SDK chain (env, shared config, SSO, container/EC2 metadata) found nothing. Packer surfaces the aggregate NoCredentialProviders when the first AWS call (AMI lookup) runs.
Edge cases
- A profile name set but the profile missing from
~/.aws/configgivesSharedCredsLoadspecifically. Check the profile name. - CI runners have no
~/.aws. Use env vars or OIDC there.
Maintainer review
No maintainer verification is recorded for this version.
This records the version a maintainer checked. It does not assert that the version is the latest upstream release.