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?

Mayor Mayer
  • 150
  • 2
  • 12
  • 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. – Mark B Oct 05 '20 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. – Mayor Mayer Oct 06 '20 at 07:59

1 Answers1

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);
});
serge
  • 1,104
  • 6
  • 6