Able to create Lambda function successfully in Lambda service. But its not automatically sending mail. Iam manually clicking on Test after the Lambda function is created. How to do it from CloudFormation.
IAM Role
"LambdaExecutionRole": {
"Type": "AWS::IAM::Role",
"Properties": {
"AssumeRolePolicyDocument": {
"Version": "2012-10-17",
"Statement": [{ "Effect": "Allow", "Principal": {"Service": ["lambda.amazonaws.com"]}, "Action": ["sts:AssumeRole"] }]
},
"Path": "/",
"Policies": [{
"PolicyName": "root",
"PolicyDocument": {
"Version": "2012-10-17",
"Statement": [{ "Effect": "Allow", "Action": ["ses:*"], "Resource": "*" }]
}
}]
} }
Lamda Fucntion
"SendEmailNotification" : {
"Type": "AWS::Lambda::Function",
"Properties": {
"Handler": "index.handler",
"Role": { "Fn::GetAtt" : ["LambdaExecutionRole", "Arn"] },
"Code": {
"ZipFile": { "Fn::Join": ["", [
"var response = require('cfn-response');\n",
"var aws = require('aws-sdk');\n",
"var ses = new aws.SES({\n",
"region:'us-east-1'\n",
"});\n",
"exports.handler = function(event, context) {\n",
"console.log('Incoming: ', event);\n",
"var eParams = {\n",
"Destination: {\n" ,
"ToAddresses: ['abc@example.com']\n",
"},\n",
"Message: {\n",
"Body: {\n",
"Text: {\n",
{"Fn::Join" : ["",["Data: '", { "Fn::ImportValue" : "SubnetId" },"'\n"]]},
"}\n",
"},\n",
"Subject: {\n",
"Data: 'Subnet'\n",
"}\n",
"},\n",
"Source: 'abc@example.com'\n",
"};\n",
"console.log('SENDING EMAIL');\n",
"var email = ses.sendEmail(eParams, function(err, data){\n",
"if(err) console.log(err);\n",
"else {\n",
"console.log('EMAIL SENT');\n",
"console.log(data);\n",
"console.log('EMAIL: ', email);\n",
"context.succeed(event);\n",
"}\n",
"});\n",
"};"
]]}
},
"Runtime": "nodejs6.10"
}
}
via Bhargav Teja
No comments:
Post a Comment