Wednesday 26 April 2017

Lambda function to use exports.handler with order of operations

I have a lambda function which is pulling messages off a SQS queue and the posting to the update alias. I would like to change the code to handle order of operations. Thanks.

'use strict'

var AWS = require('aws-sdk')
var sqs = new AWS.SQS({region : 'us-east-1'})
var lambda = new AWS.Lambda()

var params = {
AttributeNames: [
    "All"
], 
MaxNumberOfMessages: 1, 
MessageAttributeNames: [
    "All"
], 
QueueUrl: "https://sqs.", 
VisibilityTimeout: 123, 
WaitTimeSeconds: 123
};
sqs.receiveMessage(params, function(err, data) {
if (err) console.log(err, err.stack); // an error occurred
else     console.log(data);           // successful response
var params = {
    Description: "", 
    FunctionName: data.FunctionName, 
    FunctionVersion: data.Version, 
    Name: "DEV"
};
lambda.updateAlias(params, function(err, data) {
    if (err) console.log(err, err.stack); // an error occurred
    else     console.log(data);           // successful response
});
});



via kilomo

No comments:

Post a Comment