As part of a Lambda training effort, I am attempting to write a simple application that triggers a Lambda function via API Gateway. That Lambda function then connects to DynamoDB via the AWS SDK and attempts to delete an existing table.
The Lambda function fires when I perform a POST
against the API Gateway endpoint. I get a response back as {}
, which means that result
was never re-assigned beyond the initialized value. As far as I can tell the deleteTable
method never fires. I never see either the console.log()
or the console.error()
, which exist inside the body of the callback.
Please find details below:
Setup
Lambda Function
- Language: Node.Js 8.10
- Triggers: API Gateway
POST
endpoint - Execution Role Rights:
- Basic Microservice Template (Note: I've also attempting giving it explicit DynamoDB Full Access, and even Full Administrator; this didn't help anything.
Here's the code. I had something a lot more involved but trimmed it down to this when I couldn't get the delete to work:
exports.handler = async (event) => {
var aws = require('aws-sdk');
var dynamodb = new aws.DynamoDB();
var params = {
TableName: "StudyGuideSections"
};
var result = {};
dynamodb.deleteTable(params, function(err, data) {
console.log('Entering deleteTable callback...');
if (err) {
console.log(err, err.stack);
} else {
console.log(data);
result = data;
}
});
return {
statusCode: 200,
"headers": {
"Access-Control-Allow-Origin": "*"
},
body: JSON.stringify(result)
};
};
API Gateway
- Authorization: None
- Method: POST
Client-Side
- Postman (For testing)
- Simple web application executing
$.post
I've looked at the CloudWatch and X-Ray logs and I don't ever see errors, nor do I see the console.log() attempts from inside the body of the deleteTable()
call.
I'm all but pulling my hair out at this point as it has put a blocker on my training. Any help would be greatly appreciated.
Edit: For further clarification, I can change the return value's body to be something like "Hello World!" and I get that back as the response. Additionally, I can put a console.log('Attempting to delete table...")
right before the deleteTable
call; when I do that, I see it in CloudWatch. I just never see the logs from inside the deleteTable
method.
=>
after the function call. This is what I mean :dynamodb.deleteTable(params, function(err, data) =>
– AlexKdynamodb.deleteTable(params, (err, data) => {
, which I just tried and it doesn't make a difference. – Brandon Avant