Injecting credentials into a docker image for lambda usage

0

Hello,

Currently we have the following pipeline: In codebuild we build a docker image of our project and from AWS Secret manager we inject a ".env" file into the image. This image is uploaded to AWS ECR and then deployed into a lambda function, but the lambda function is not been able to find the enviroment variables. We are doing this to avoid writing secrets into the lambda console and having all credentials in one place.

How can i load this .env file so the lambda can read the credentials? It has to be in a particular folder (its in the root of the project) or is not possible to do what we are trying to do? whats the path of the image where all env variables goes?

We are using this image FROM public.ecr.aws/lambda/nodejs:14 for the docker

ignacio
已提问 4 个月前300 查看次数
2 回答
2

Hi,

AWS Secrets Manager is a service built exactly to serve your use case: https://aws.amazon.com/secrets-manager/

More detals on using secrets frol Lambda: https://docs.aws.amazon.com/secretsmanager/latest/userguide/retrieving-secrets_lambda.html

By the way, you .env file should also probably not be in your container image but also accessed in SM by the container. Simlar code to Lambda should be used in the container to access the secret(s)

Best,

Didier

profile pictureAWS
专家
已回答 4 个月前
profile picture
专家
已审核 4 个月前
1

Please read the envirnoment variable as per the below the sample code: Step 1: Node js apps const dotenv = require('dotenv'); dotenv.config(); // This will read from your .env file and set the environment variables Step 2: copy the value from envirnoment variable

FROM public.ecr.aws/lambda/nodejs:14 WORKDIR /var/task COPY . . # Copy your application code and .env file ENV VAR_NAME=value

profile picture
Jagan
已回答 4 个月前

您未登录。 登录 发布回答。

一个好的回答可以清楚地解答问题和提供建设性反馈,并能促进提问者的职业发展。

回答问题的准则