This repository was archived by the owner on Aug 9, 2026. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathlambda.json
More file actions
108 lines (108 loc) · 3.44 KB
/
Copy pathlambda.json
File metadata and controls
108 lines (108 loc) · 3.44 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
{
"AWSTemplateFormatVersion" : "2010-09-09",
"Description" : "Lambda diagnostic endpoint file creation",
"Parameters" : {
"BucketName": {
"NoEcho": "true",
"Type": "String",
"Description" : "S3 bucket name to put the file",
},
"FileName": {
"NoEcho": "true",
"Type": "String",
"Description" : "File name to put in the S3 bucket",
},
"FileContent": {
"NoEcho": "true",
"Type": "String",
"Description" : "File content in string",
},
"ScheduleExpression": {
"NoEcho": "true",
"Type": "String",
"Description" : "ScheduleExpression - refer http://docs.aws.amazon.com/AmazonCloudWatch/latest/events/ScheduledEvents.html",
}
},
"Resources": {
"LambdaFuctionRole": {
"Type": "AWS::IAM::Role",
"Properties": {
"AssumeRolePolicyDocument": {
"Version": "2012-10-17",
"Statement": [
{
"Action": "sts:AssumeRole",
"Principal": {
"Service": "lambda.amazonaws.com"
},
"Effect": "Allow",
"Sid": ""
}
]
},
"Policies": [
{
"PolicyName": "Policy",
"PolicyDocument": {
"Version": "2012-10-17",
"Statement": [{ "Effect": "Allow", "Action": ["s3:PutObject"], "Resource": "arn:aws:s3:::*" }]
}
}
]
}
},
"LambdaFunction": {
"Type": "AWS::Lambda::Function",
"Properties": {
"Code": {
"ZipFile": { "Fn::Join": ["", [
"var AWS = require('aws-sdk');",
"exports.handler = function(event, context) {",
" var s3 = new AWS.S3();",
" var param = ",
"{Bucket: '",
{ "Ref":"BucketName"},
"', Key: '",
{ "Ref":"FileName"},
"', Body: '",
{ "Ref":"FileContent"},
"'};",
" s3.upload(param, function(err, data) {",
" if (err) console.log(err, err.stack);",
" else console.log(data);",
" console.log('Great Success');",
" context.done();",
"});}"
]]}
},
"Handler": "index.handler",
"Role": {"Fn::GetAtt": ["LambdaFuctionRole", "Arn"]},
"Runtime": "nodejs4.3",
"Timeout": 10
}
},
"ScheduledEventRule": {
"Type": "AWS::Events::Rule",
"Properties": {
"Description": "Scheduled Lambda Invocation Rule",
"ScheduleExpression": { "Ref":"ScheduleExpression"},
"State": "ENABLED",
"Targets": [
{
"Id": "LambdaFunctionTarget",
"Arn": {"Fn::GetAtt": ["LambdaFunction", "Arn"]}
}
]
}
},
"InvokeLambdaPermission": {
"Type": "AWS::Lambda::Permission",
"Properties": {
"Action": "lambda:InvokeFunction",
"Principal": "events.amazonaws.com",
"SourceArn": {"Fn::GetAtt": ["ScheduledEventRule", "Arn"]},
"FunctionName": {"Fn::GetAtt": ["LambdaFunction", "Arn"]}
}
}
}
}