boto3: config profile could not be found

Viewed 653

I'm testing my lambda function wrapped in a docker image and provided environment variable AWS_PROFILE=my-profile for the lambda function. However, I got an error : "The config profile (my-profile) could not be found" while this information is there in ~/.aws/credentials and ~/.aws/config files. Below are my commands:

docker run -e BUCKET_NAME=my-bucket -e AWS_PROFILE=my-profile-p 9000:8080 <image>:latest lambda_func.handler
curl -XPOST "http://localhost:9000/2015-03-31/functions/function/invocations" -d '"body":{"x":5, "y":6}}'

The thing is that if I just run the lambda function as a separated python script then it works.

Can someone show me what went wrong here? Thanks

2 Answers

When AWS is showing how to use their containers, such as for local AWS Glue, they share the ~/.aws/ in read-only mode with the container using volume option:

-v ~/.aws:/root/.aws:ro

Thus if you wish to follow AWS example, your docker command could be:

docker run -e BUCKET_NAME=my-bucket -e AWS_PROFILE=my-profile-p 9000:8080 -v ~/.aws:/root/.aws:ro <image>:latest lambda_func.handler

The other way is to pass the AWS credentials using docker environment variables, which you already are trying.

Related