I am trying to use aws-sdk inside lambda but I can't seem to figure it out.
var AWS = require('aws-sdk');
AWS.config.update();
var DDB = new AWS.DynamoDB({ apiVersion: "2012-10-08" });
exports.handler = function (event, context, callback) {
var url_handler = event.requestContext.domainName + "/" + event.requestContext.stage;
var scanParams = {
TableName: "tbl-web-socket-connection",
ProjectionExpression: "id"
};
DDB.scan(scanParams, function (err, data) {
console.log(err, "Error");
if (err) {
callback(null, {
statusCode: 500,
body: JSON.stringify(err)
});
} else {
console.log(AWS, "AWSSS");
var apigwManagementApi = new AWS.ApiGatewayManagementApi({
apiVersion: "2018-11-29",
endpoint: event.requestContext.domainName + "/" + event.requestContext.stage
});
}
});
};
This is what I declaered on the lambda function, but it gives giving me the error "AWS.ApiGatewayManagementApi is not a constructor at Response." on the cloud watch.
Did I miss something? Like maybe including the aws-sdk on the lambda function itself?
Edit: Updated to display the whole lambda function
To those people who have the same problem as me
It looks like that the version of “aws-sdk” available in lambda execution is 2.29 ApiGatewayManagementApi is added in 2.379
That's why it cannot call the constructor.
To solve this problem, I created a layer with the aws-sdk with it and add those layer to the lambda function.
As of May 15, 2019 you can run the Lambda as node version 10.x and the ApiGatewayManagementApi is included in the aws-sdk by default.
https://aws.amazon.com/about-aws/whats-new/2019/05/aws_lambda_adds_support_for_node_js_v10/
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With