Looks as really simple task but it's difficult to find good example on it.
So, the task is following: AWS lambda puts some message to AWS-SQS.
Code of AWS lambda contains such line:
var QUEUE_URL = 'https://sqs.us-west-2.amazonaws.com/ID/QUEUE_NAME';",
In order to get rid of this code there are possible two options:
- Create query that will lookup this queue based on region and queue name SQS has predictable names;
- Create Cloud Formaion script and specify these dependencies there.
Based on this fact that periodic trigger (lambda) will work many times a day it's better to specify this dependency duting deployment.
In general it looks like as straight forward task and cloud formations script was created:
"Resources": {
"LF2HNR1": {
"Type": "AWS::Lambda::Function",
"Properties": {
"Description": "This is lambda trigger",
"Handler": "index.myHandler",
"Runtime": "nodejs",
"Timeout": "300",
And also dependency was specified that lambda depends on SQS:
"DependsOn": [
"SQSQ562D4"
]
},
"SQSQ562D4": {
"Type": "AWS::SQS::Queue",
"Properties": {},
}
Hovewer it's not stright forward task how to programmatically get SQS url in lambda code:
exports.handler = function(event, context) {
var params = {
MessageBody: JSON.stringify(event),
var QUEUE_URL = ????