Created
November 2, 2016 22:20
-
-
Save Kalimaha/b2474de7a4c4f7d704ba6dd7967da50e to your computer and use it in GitHub Desktop.
AWS Lambda function to configure an Existing S3 Bucket
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| LambdaFunction: | |
| Type: "AWS::Lambda::Function" | |
| DependsOn: SNSTopic | |
| Properties: | |
| Description: "Lambda function to modify the existing S3 bucket" | |
| Handler: index.handler | |
| Runtime: "nodejs4.3" | |
| Timeout: 300 | |
| Role: !GetAtt [ LambdaFunctionRole, Arn ] | |
| Code: | |
| ZipFile: | |
| Fn::Join: | |
| - '' | |
| - - "var AWS = require('aws-sdk'); \n" | |
| - "var response = require('cfn-response'); \n" | |
| - "var S3 = new AWS.S3(); \n" | |
| - "exports.handler = function(event, context) { \n" | |
| - " var params = { \n" | |
| - " Bucket: '" | |
| - !Ref BucketName | |
| - "', \n" | |
| - " NotificationConfiguration: { \n" | |
| - " TopicConfigurations: [{ \n" | |
| - " Events: [ 's3:ObjectCreated:*' ], \n" | |
| - " TopicArn: '" | |
| - !Ref SNSTopic | |
| - "', \n" | |
| - " Filter: { Key: { FilterRules: [{ \n" | |
| - " Name: 'prefix', \n" | |
| - " Value: '" | |
| - !Ref BucketFilePrefix | |
| - "' \n" | |
| - " }] } } \n" | |
| - " }] \n" | |
| - " } \n" | |
| - " }; \n" | |
| - " S3.putBucketNotificationConfiguration(params, function(err, data) { \n" | |
| - " if (err) { response.send(event, context, response.FAILURE, {}); } \n" | |
| - " else { response.send(event, context, response.SUCCESS, {}); } \n" | |
| - " }); \n" | |
| - "}; \n" |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment