Skip to content

Instantly share code, notes, and snippets.

@akleiber
Created June 8, 2016 19:39
Show Gist options
  • Save akleiber/9d0738ebcc8f85e5a04a6a2666b1e964 to your computer and use it in GitHub Desktop.
Save akleiber/9d0738ebcc8f85e5a04a6a2666b1e964 to your computer and use it in GitHub Desktop.
AWS Lambda sample: Send received events to SQS as Message
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
}
});
}
#!/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