How to use the Lambda function from aws-sdk

Find comprehensive JavaScript aws-sdk.Lambda code examples handpicked from public code repositorys.

The aws-sdk.Lambda is a client object in AWS SDK for Node.js that provides methods to access and manage AWS Lambda services.

1
2
3
4
5
6
7
8
9
10
let waterfall = require('run-waterfall')

module.exports = function route({api, env, name, region, account, RouteKey}, callback) {

  let gateway = new aws.ApiGatewayV2({region})
  let lambda = new aws.Lambda({region})

  let arn = `arn:aws:lambda:${region}:${account}:function:${name}-${env}-ws-${RouteKey.replace('$', '')}`

  // used later
fork icon99
star icon0
watch icon3

76
77
78
79
80
81
82
83
84
85
console.log(event);
console.log(context);

var ec2 = new AWS.EC2();
var cloudwatchevents = new AWS.CloudWatchEvents();
var lambda = new AWS.Lambda();
var ImageId;
var RuleArn;

function waterfall(arr, cb) {
fork icon19
star icon122
watch icon7

How does aws-sdk.Lambda work?

aws-sdk.Lambda is a Node.js module that provides methods for managing AWS Lambda functions programmatically, including invoking functions, creating new functions, and managing existing ones. The aws-sdk.Lambda constructor takes an optional configuration object that can be used to set various options, such as the AWS region to use, and returns an instance of the Lambda class, which has methods that correspond to different Lambda API actions. For example, you can use the invoke method to invoke a Lambda function, the createFunction method to create a new function, and the updateFunctionCode method to update an existing function's code.

90
91
92
93
94
95
96
97
98
99

```JavaScript
'use strict'

const aws = require('aws-sdk');
const lambda = new aws.Lambda({
  region: 'ap-northeast-1' //change to your region
});

const event = { id: "1", name:"Luna"};
fork icon20
star icon61
watch icon9

10
11
12
13
14
15
16
17
18
19
    region
  }
}

lambda () {
  const lambda = new AWS.Lambda(this.config);
  return lambda;
}

apigatewayv2 () {
fork icon3
star icon2
watch icon4

Ai Example

1
2
3
4
5
6
7
8
9
10
11
12
13
const AWS = require("aws-sdk");
const lambda = new AWS.Lambda({ region: "us-east-1" });

const params = {
  FunctionName: "myLambdaFunction",
  InvocationType: "RequestResponse",
  Payload: JSON.stringify({ key: "value" }),
};

lambda.invoke(params, function (err, data) {
  if (err) console.log(err, err.stack);
  else console.log(data);
});

In this example, we first create a new instance of the AWS.Lambda class, passing in the region where our Lambda function is deployed. We then define the params object that specifies the name of our Lambda function, the type of invocation we want to make, and the payload we want to send. Finally, we call the invoke method on our lambda object, passing in the params object and a callback function to handle the response from the Lambda function. If there is an error, we log it to the console. Otherwise, we log the response from the Lambda function.

14
15
16
17
18
19
20
21
22
let path = require("path");
const zipLocal = require("zip-local");


const AWS = require('aws-sdk');
const lambda = process.env.METRICS == "true" ? new AWS.Lambda({ customUserAgent: process.env.SOLUTION_IDENTIFIER, region: 'us-east-1' }) : new AWS.Lambda({ region: 'us-east-1' });
const ssm = process.env.METRICS == "true" ? new AWS.SSM({ customUserAgent: process.env.SOLUTION_IDENTIFIER }) : new AWS.SSM();
const wafv2 = process.env.METRICS == "true" ? new AWS.WAFV2({ customUserAgent: process.env.SOLUTION_IDENTIFIER, region: 'us-east-1' }) : new AWS.WAFV2({ region: 'us-east-1' });

fork icon5
star icon12
watch icon15

29
30
31
32
33
34
35
36
37
var apigateway = new AWS.APIGateway({
  region: config.AWS.region,
  apiVersion: config.AWS.APIGateway.apiVersion
});

var lambda = new AWS.Lambda({
  region: config.AWS.region,
  apiVersion: config.AWS.Lambda.apiVersion
});
fork icon0
star icon5
watch icon2

-3
fork icon3
star icon3
watch icon3

+ 84 other calls in file

27
28
29
30
31
32
33
34
35
36
  daily: 'rate(1 day)'
}

function scheduleBackup (options) {
  let events = new AWS.CloudWatchEvents({ apiVersion: '2015-10-07', region: options.s3Region })
  let lambda = new AWS.Lambda({ apiVersion: '2015-03-31', region: options.s3Region })
  let addPermission = promisify(lambda.addPermission.bind(lambda))
  let listRules = promisify(events.listRules.bind(events))
  let putRule = promisify(events.putRule.bind(events))
  let putTargets = promisify(events.putTargets.bind(events))
fork icon2
star icon3
watch icon5

+ 5 other calls in file

20
21
22
23
24
25
26
27
28

        AWS.config.credentials = new AWS.SharedIniFileCredentials(objectCredentials);
}

this._apiGateway = utils.pify(new AWS.APIGateway());
this._lambda = utils.pify(new AWS.Lambda());

this._exec = function (method, params, retry) {
        retry = retry || 0;
fork icon2
star icon1
watch icon4

5
6
7
8
9
10
11
12
13
14
        awsRegion = require('./test-aws-region'),
        originalWorkingDir = process.cwd();

module.exports = function destroyObjects(newObjects) {
        'use strict';
        const lambda = new aws.Lambda({ region: awsRegion }),
                logs = new aws.CloudWatchLogs({ region: awsRegion }),
                apiGatewayPromise = retriableWrap(new aws.APIGateway({ region: awsRegion })),
                s3 = new aws.S3(),
                iot = new aws.Iot({ region: awsRegion }),
fork icon290
star icon0
watch icon3

17
18
19
20
21
22
23
24
25
26
27
const https = require("https");
const crypto = require("crypto");
const querystring = require("querystring");
const zlib = require("zlib");
const coralogix = require("coralogix-logger");
const lambda = new aws.Lambda();


// Check Lambda function parameters
assert(process.env.CORALOGIX_PRIVATE_KEY, "No Coralogix Private Key!");
assert(process.env.MONGODB_ATLAS_PUBLIC_API_KEY, "MongoDB Atlas Public API key is not set");
fork icon4
star icon0
watch icon14

+ 31 other calls in file

2
3
4
5
6
7
8
9
10
11
12
13
exports.handler = async function(event) {
  console.log("request:", JSON.stringify(event, undefined, 2));


  // create AWS SDK clients
  const dynamo = new DynamoDB();
  const lambda = new Lambda();


  // update dynamo entry for "path" with hits++
  await dynamo.updateItem({
    TableName: process.env.HITS_TABLE_NAME,
fork icon0
star icon1
watch icon1

+ 9 other calls in file

2
3
4
5
6
7
8
9
10
11
12
13
let mastodonSend = require('./mastodon-send.js');
let config = require('./config/config-mastodon.json');
let parser = require('./mastodon-contentparser.js');


let AWS = require("aws-sdk");
let lambda = new AWS.Lambda();


const MAX_LENGTH_CONT_MESSAGE = " [cont.]";
const REPLY_HASHTAGS = "\n\n#zork #interactivefiction";

fork icon0
star icon0
watch icon1

+ 2 other calls in file

6
7
8
9
10
11
12
13
14
15
16
17
18
//const {checkSecret, getSecret} = require('/opt/nodejs/utils')
const AWS = require('aws-sdk');


const lambdaNames = { DB: process.env.FUNCTION_UPLOADDYNAMO_NAME, S3: process.env.FUNCTION_FILEUPLOAD_NAME };


const lambda = new AWS.Lambda();


exports.handler = async (event) => {
  console.log('event', event);
  let response;
fork icon0
star icon0
watch icon1

+ 3 other calls in file

15
16
17
18
19
20
21
22
23
24
25


let lambda;
let sqs;
const AWS = require('aws-sdk');
if (process.env.IS_OFFLINE === 'false') {
  lambda = new AWS.Lambda({
    region: process.env.AWS_REGION //change to your region
  });
  // Create an SQS service object
  AWS.config.update({ region: process.env.AWS_REGION });
fork icon0
star icon0
watch icon0

+ 24 other calls in file

1
2
3
4
5
6
7
8
9
10
11
12
13


exports.handler = async function (event) {
  console.log('Request:', JSON.stringify(event, undefined, 2))


  const dynamo = new DynamoDB()
  const lamda = new Lambda()


  await dynamo
    .updateItem({
      TableName: process.env.HITS_TABLE_NAME,
fork icon0
star icon0
watch icon1

+ 17 other calls in file

32
33
34
35
36
37
38
39
40
  return fixtures.enableDataApiFixtures()
})

afterEach(() => {
  kinesisWrites = {}
  AWS.Lambda.restore()
  kmsHelperPcdm.decrypt.restore()
  scsbClient.search.restore()
  NyplStreamsClient.prototype.write.restore()
fork icon0
star icon0
watch icon7

+ 30 other calls in file

3
4
5
6
7
8
9
10
11
12
13
const ddb = new AWS.DynamoDB({
    apiVersion: '2012-08-10',
    endpoint: process.env.dynamoEndpoint
});


const lambda = new AWS.Lambda({
    apiVersion: "2015-03-31",
    endpoint: process.env.lambdaEndpoint
});

fork icon0
star icon0
watch icon1

+ 43 other calls in file

106
107
108
109
110
111
112
113
114
115

/**
 * Invoke S3JsonLoggerFunction so that a log entry containing the file content is sent to cloudwatch
 */
const invokeFunction = async () => {
  const client = new AWS.Lambda();
  const response = await client
    .invoke({
      FunctionName: functionName,
      InvocationType: "Event",
fork icon0
star icon0
watch icon1

+ 14 other calls in file