1

in the SAM documentation there is the possibility shown to deploy your own lambda endpoint and call it with the Python SDK.

You just have to startup the local lambda endpoint with sam local start-lambda and then continue with

# USING AWS SDK
 -------------
 #You can also use the AWS SDK in your automated tests to invoke your functions programatically.
 #Here is a Python example:

     self.lambda_client = boto3.client('lambda',
                                  endpoint_url="http://127.0.0.1:3001",
                                  use_ssl=False,
                                  verify=False,
                                 config=Config(signature_version=UNSIGNED,
                                               read_timeout=0,
                                                retries={'max_attempts': 0}))
    self.lambda_client.invoke(FunctionName="HelloWorldFunction")

My question is now, how can i do exactly the same with the Javascript SDK? I always get different errors about missing regions, not found hosts and unsupported parameters. Do you have a solution for me?

2
  • 1
    Instead of saying "I get these errors when I try" show the actual code, and the actual error message, so we can help. We are here to help with issues, we are not here to provide a free code conversion service. Commented Oct 5, 2020 at 16:56
  • Yes i know, i was a bit in a hurry yesterday. Normally i provide enough code to understand my problems better. I vow improvement. Commented Oct 6, 2020 at 7:59

1 Answer 1

5

AWS JavaScript SDK requires region and credentials to make requests. But for local endpoints you can use arbitrary values.

Following example works for me:

const AWS = require('aws-sdk');

const lambda = new AWS.Lambda({
  apiVersion: '2015-03-31',
  endpoint: 'http://127.0.0.1:3001',
  sslEnabled: false,
  region: 'us-east-1',
  accessKeyId: 'any',
  secretAccessKey: 'any'
});

lambda.invoke({
  FunctionName: 'HelloWorldFunction'
}, (err, res) => {
  console.log(res);
});
Sign up to request clarification or add additional context in comments.

1 Comment

Thanks you very much. My code looked almost the same, but something simply didn't work.

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.