Last active
August 2, 2022 13:12
-
-
Save johntdyer/7f9b3fc422e7b370c29ba83e70ec1c81 to your computer and use it in GitHub Desktop.
AWS Lambda sample: Send received events to SQS as Message
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// PUT YOUR AWS ACCOUNT NUMBER HERE | |
var AWS_ACCOUNT_ID= '12345'; | |
// PUT YOUR SQS QUEUE NAME HERE | |
var AWS_SQS_QUEUE_NAME='catch-dlr-dyer-testing'; | |
var QUEUE_URL = 'https://sqs.us-east-1.amazonaws.com/' + AWS_ACCOUNT_ID + '/' + AWS_SQS_QUEUE_NAME; | |
var AWS = require('aws-sdk'); | |
var sqs = new AWS.SQS({region : 'us-east-1'}); | |
exports.handler = function(event, context) { | |
var params = { | |
MessageBody: JSON.stringify(event), | |
QueueUrl: QUEUE_URL | |
}; | |
sqs.sendMessage(params, function(err,data){ | |
if(err) { | |
console.log('error:',"Fail Send Message" + err); | |
context.done('error', "ERROR Put SQS"); // ERROR with message | |
}else{ | |
console.log('data:',data.MessageId); | |
context.done(null,''); // SUCCESS | |
} | |
}); | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/bin/sh | |
FUNCTION_JS=sendsqs.js | |
FUNCTION_FILE=sendsqs.zip | |
FUNCTION_NAME=sendsqs | |
ROLE_NAME=lambda_exec_role_dyer | |
AWS_ACCOUNT_ID=12345 | |
REGION=us-east-1 | |
DESCRIPTION=dlr-webhook-to-sqs | |
EXEC_ROLE="arn:aws:iam::$AWS_ACCOUNT_ID:role/$ROLE_NAME" | |
zip $FUNCTION_FILE $FUNCTION_JS | |
aws lambda create-function \ | |
--region $REGION \ | |
--function-name $FUNCTION_NAME \ | |
--zip-file fileb://$FUNCTION_FILE \ | |
--role $EXEC_ROLE \ | |
--handler $FUNCTION_NAME.handler \ | |
--runtime nodejs4.3 \ | |
--description $DESCRIPTION \ | |
--timeout 60 \ | |
--memory-size 128 \ | |
--debug |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment