-
Notifications
You must be signed in to change notification settings - Fork 51
/
Copy pathcustom-resource-demo-final.yml
58 lines (50 loc) · 1.85 KB
/
custom-resource-demo-final.yml
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
Description: >
Simple custom resource demo
Parameters:
BucketName:
Type: String
Description: The name of the s3 bucket you want to create
RoleForLambda:
Description: ARN of the role you created
Type: String
Resources:
MyCustomResourceFunction:
Type: AWS::Lambda::Function
Properties:
Code:
ZipFile: |
var response = require('cfn-response');
var aws = require("aws-sdk");
exports.handler = function(event, context) {
var responseText = "starting function"
var s3 = new aws.S3();
var bucketName = event.ResourceProperties.BucketName;
responseText = "got bucket name: " + bucketName
if ( event.RequestType == 'Create' ) {
s3.createBucket( { Bucket: bucketName }, function(err,data) {
responseText = "failed to create bucket " + bucketName + ": " + err
})
} else if ( event.RequestType == 'Delete' ) {
s3.deleteBucket({Bucket: bucketName}, function(err,data){
responseText = "failed to delete bucket " + bucketName + ": " + err
})
}
var responseData = {msg: "hello world!", responseText: responseText};
response.send(event, context, response.SUCCESS, responseData);
};
Handler: index.handler
Timeout: 30
Runtime: nodejs14.x
Role: !Ref RoleForLambda
MyCustomResourceCallout:
Type: Custom::LambdaCallout
Properties:
ServiceToken: !GetAtt MyCustomResourceFunction.Arn
BucketName: !Ref BucketName
Outputs:
OutputFromFunction:
Description: Output from the custom function
Value: !GetAtt MyCustomResourceCallout.msg
ResponseText:
Description: Output from the custom function
Value: !GetAtt MyCustomResourceCallout.responseText