AWS Lambda sample: Send received events to SQS as Message
#!/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
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
}
});
}