I am trying to set custom endpoint URL with AWS CLI to point to Localstack. This command works perfectly:
AWS_ACCESS_KEY_ID=test AWS_SECRET_ACCESS_KEY=test aws --endpoint-url=http://localhost:4566 s3 ls
However, for some reason, I don’t want to use --endpoint-url
option. I need to use environment variables. I read in the documentation about AWS_ENDPOINT_URL
variable and I tried this:
AWS_ACCESS_KEY_ID=test AWS_SECRET_ACCESS_KEY=test AWS_ENDPOINT_URL=http://localhost:4566 aws s3 ls
But I get this error:
An error occurred (InvalidAccessKeyId) when calling the ListBuckets
operation: The AWS Access Key Id you provided does not exist in our
records.
It seems it’s not going to Localstack, at least the AWS STS. I tried also setting the variables AWS_ENDPOINT_URL_STS
and AWS_ENDPOINT_URL_S3
to http://localhost:4566, but I get the same error.
2
Answers
If you wish not to use
--endpoint-url
, you can use a custom profile. Add the following profile to your AWS configuration file (by default, this file is at~/.aws/config
):Add the following profile to your AWS credentials file (by default, this file is at
~/.aws/credentials
):You can now use the
localstack profile
with theaws
CLI:The command that you shared shouldn’t ideally create an issue (it works on my end with
aws-cli/2.13.32 Python/3.11.6 Darwin/21.4.0 exe/x86_64 prompt/off
) but it would be worth checking your CLI version.According to the changelog:
The endpoint URL configuration via environment variable was added in version 2.13.0, released around Jul 7, 2023.
Updating the AWS CLI to update to the latest version should fix this issue.