Created
June 8, 2016 19:39
-
-
Save akleiber/9d0738ebcc8f85e5a04a6a2666b1e964 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
var QUEUE_URL = 'https://sqs.us-east-1.amazonaws.com/{AWS_ACCUOUNT_}/matsuoy-lambda'; | |
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 | |
REGION=us-east-1 | |
EXEC_ROLE='arn:aws:iam::{AWS_ACCUOUNT_}:role/lambda_exec_role' | |
zip $FUNCTION_FILE $FUNCTION_JS | |
aws lambda upload-function \ | |
--region $REGION \ | |
--function-name $FUNCTION_NAME \ | |
--function-zip $FUNCTION_FILE \ | |
--role $EXEC_ROLE \ | |
--mode event \ | |
--handler $FUNCTION_NAME.handler \ | |
--runtime nodejs \ | |
--description "test" \ | |
--timeout 60 \ | |
--memory-size 128 \ | |
--debug |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment