2
votes

I'm using Elastic Beanstalk to run a flask app. I want to use DynamoDB as the database. In order to access DynamoDB, I'm using PynamoDB, which access DynamoDB service by botocore. As the AWS document says, I have created the credentials file at ~/.aws/credentials on my Mac and set the AWS user access_key. The flask app can access DynamoDB running on my Mac. However, after deploy to Elastic Beanstalk by eb deploy, I don't know to how to add the credentials file.

I have tried:

  1. copy the credentials file under my project root directory. and create a config file: 02_dynamodb.config under .ebextensions.
commands:
  01makecredentials:
    command: mkdir ~/.aws/;cp ./credentials ~/.aws/credentials

it failed to deploy after adding the config file.

  1. I have read the botocore document, which says that I can set the access_key by session. However, PynamoDB could not use a custom session. It will create a session if it need and the session will read access_key from ~/.aws/credentials, or .boto

I have read lots of document but don't know how to set the access_key to botocore application after deploying the app to Elastic Beanstalk. The AWS document only tell me how to set the access_key on my development Mac.

Any help would be appreciate.

Update Thanks @mbaird! The solution is to grant DynamoDB Access permission for aws-elasticbeanstalk-ec2-role!

1
you can manually set the environment vars from the shell of the machine where you are running your code. i.e, 'export AWS_ACCESS_KEY_ID=value'. You need to do that for secret access key and region as well. See the link: docs.aws.amazon.com/cli/latest/userguide/…phoenix

1 Answers

3
votes

The preferred way to do this sort of thing is by giving the required access to an IAM role that is assigned to your Elastic Beanstalk servers. Then you don't have to create credential files at all.

You can read the reasons this is considered a best practice here.