skip to Main Content

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


  1. 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):

    [profile localstack]
    region=us-east-1
    output=json
    endpoint_url = http://localhost:4566
    

    Add the following profile to your AWS credentials file (by default, this file is at ~/.aws/credentials):

    [localstack]
    aws_access_key_id=test
    aws_secret_access_key=test
    

    You can now use the localstack profile with the aws CLI:

    aws s3 mb s3://test --profile localstack
    aws s3 ls --profile localstack
    

    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.

    Login or Signup to reply.
  2. According to the changelog:

    2.13.0

    feature:configuration: Configure the endpoint URL in the shared configuration file or via an environment variable for a specific AWS service or all AWS services.

    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.

    Login or Signup to reply.
Please signup or login to give your own answer.
Back To Top
Search