Search code examples
amazon-web-servicesenvironment-variablesamazon-elastic-beanstalkaws-sdk-jsaws-sdk-js-v3

node application using AWS SDK v3 DynamoDB Client deployed to AWS beanstalk cannot read env. variables


I have a nodejs application which uses AWS SDK for JavaScript v3 client-dynamodb. The application is deployed to an AWS beanstalk environment where I have created two environment properties for AWS_Access_key_ID and AWS_Secret_access_key. The documentation says:

The SDK automatically detects AWS credentials set as variables in your environment and uses them for SDK requests. This eliminates the need to manage credentials in your application

However, the deployed application can't seem to detect the env variables automatically. Using v2, I did not have this problem as I could programatically provide the access key and access ID as configs after reading them from the process.env, but in v3 there doesn't seem to be a way to do that.

I also do not want to mess with the EC2 instance manually as I have a code pipeline which updates the beanstalk on every push to the repo and everything is managed automatically.

Any suggestions? I thought of adding my env. variables to the YAML file which is used when building the environment but I am not sure how those variables would differ from the beanstalk env. variables.


Solution

  • As jarmod mentioned there are better ways to do what I wanted to achieve.

    Particularly this document helped me to fix the issue. I attached a new policy to my aws-elasticbeanstalk-ec2-role to have full access to DynamoDB.

    It would have been nice if AWS SDK for JavaScript v3 mentioned that the automatic recognition of environment variables does not work on beanstalk environment properties which I have been using as normal env. vars. It could have saved me time!