Giter Site home page Giter Site logo

Comments (8)

mhart avatar mhart commented on August 27, 2024 2

Are you using the -e flag to pass the env variables to docker?

Try docker run -e AWS_ACCESS_KEY_ID -e AWS_SECRET_ACCESS_KEY run -v "$PWD/dist":/var/task lambci/lambda

That will use whatever those variables are set to in your current env. If you want to supply a specific value, use -e AWS_ACCESS_KEY_ID=whatever

from docker-lambda.

mhart avatar mhart commented on August 27, 2024 1

Closing as it seems the root cause of the issue has been found πŸ‘

from docker-lambda.

nnnikolay avatar nnnikolay commented on August 27, 2024

Damn it, I completely forgot about the -e option :) Thanks, for the advice.
Looks like it works now!

But I still don't understand why NodeJS could not get them from the .env file. They are listed there. Why they were not available for the application?

Thanks!

from docker-lambda.

mhart avatar mhart commented on August 27, 2024

It depends on how you're defining them. Are you doing it outside of the Lambda function, at the top-level during require time? Those variables are overridden each time Lambda executes – this is true in the live Lambda environment too – so unless you define them in your function body (which is not a good idea – you should manage your credentials using IAM in Lambda) – they will be overridden by the Lambda environment (or in this case, by the docker-lambda controlling code)

from docker-lambda.

nnnikolay avatar nnnikolay commented on August 27, 2024

Oh, I did not know that.

I'm doing it like that

var main = function (ctx, cb) {
  // load .env file and place variables into process.env.VARIABLE_NAME
 require('dotenv').config();


...

exports.handler = function (e, ctx, cb) {
  main(ctx, cb);
};

I'm sorry but

you should manage your credentials using IAM in Lambda

Could you please point me to the documentation page where I can see the description how to achieve that?

from docker-lambda.

mhart avatar mhart commented on August 27, 2024

See https://www.npmjs.com/package/dotenv#what-happens-to-environment-variables-that-were-already-set

from docker-lambda.

mhart avatar mhart commented on August 27, 2024

Lambda will already set your AWS_ACCESS_KEY_ID and AWS_SECRET_ACCESS_KEY variables – so you won't be able to override them using dotenv.

Again, you really shouldn't be storing or loading these variables in Lambda itself (for testing it's fine, but you shouldn't be doing it via dotenv – use the -e flag)

Lambda will assign those variables using temporary IAM credentials based on the IAM role that the Lambda is running. That's where you should manage all of your Lambda permissions – using the Role that you've assigned to the Lambda.

See more info here: http://docs.aws.amazon.com/lambda/latest/dg/intro-permission-model.html

from docker-lambda.

nnnikolay avatar nnnikolay commented on August 27, 2024

Oh ok, now I got it.

Thank you.

from docker-lambda.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    πŸ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. πŸ“ŠπŸ“ˆπŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❀️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.