Home > Net >  Boto3 cannot find aws credentials on pycharm when using remote interpreter
Boto3 cannot find aws credentials on pycharm when using remote interpreter

Time:11-17

I'm using a remote interpreter on PyCharm (docker container) and need to connect to AWS. My credentials work fine on the cli, even with the aws toolkit, but boto3 cannot find them. How do I set it up properly?

CodePudding user response:

The Docker container does not have access to your aws credentials from the host machine. There are several ways to solve this, the easiest being passing your aws access key and secret key as environment variables for the Docker container. For example:

To your Dockerfile you can add the following:

ENV AWS_ACCESS_KEY_ID=AKIAIOSFODNN7EXAMPLE
ENV AWS_SECRET_ACCESS_KEY=...

Other ways might be to have an .env file if you are using docker-compose or mounting ~/.aws folder from the host machine as a volume inside the Docker container.

Keep in mind that these solutions work for local development using Docker. Sharing your credentials is not recommended from a security perspective, moreover pushing them to a version control repository is a really bad idea.

In order to make it more secure, you may want to create a role for your application in AWS and use assume-role to get temporary AWS credentials for that role, which might be passed to the Docker container.

  • Related