2

I have Lambda setup locally using Docker and Sam. I can hit an endpoint and run the Lambda method locally, but if i want to test the below code, I have to actually deploy the Lambda since I'm not sure how to get the aws-sdk to work in a local environment.

    const payload = JSON.stringify({
      "bucket": process.env.AWS_S3_ENV_BUCKET,
      "region": process.env.AWS_REGION,
      "folder": 'somePath/',
      "files": ['somefile.jpg', 'anotherfile.jpg'],
      "zipFileName": 'zipZippedFile.zip'
    })

    const params = {
      FunctionName: 'zippidyDoDah',
      Payload: payload
    }

    global.Lambda.invoke(params, function (error, data) {
      console.log('error: ', error)
      console.log('data: ', data)
    })
    

Does anyone have any insight on this?

1 Answer 1

1

If you install the AWS Command Line Interface and run an aws configure you can enter the access key and secret key of the user that you want this code to be executed as. These credentials are stored in ~/.aws/credentials. You should be able to inject the AWS CLI and these credentials into your docker container and (assuming they are your [default]) they should get picked up automatically by your process. You should read about AWS CLI Profiles too.

Sign up to request clarification or add additional context in comments.

3 Comments

Jarred, it seems like you are suggesting that I can create a new AWS CLI Profile for the AWS Lamba methods locally on my computer. Would this mean that I would have a different region, secret key, etc. for running the Lamba's locally? I think I might not be understanding something correctly.
Your region would be the same as your deployed lambda named 'zippidyDoDah'. Setting up your credentials locally (or inside your docker conainter) would allow you to invoke the lambda 'zippidyDoDah' running in AWS from your local. Does this help?
This helps a great deal! When I get back to working on this, I will post a more detailed solution for those needing help in the future. Much appreciated!

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.