Created
May 30, 2016 20:07
-
-
Save linyatis/d684cff4ff8e02972d53ae87b5c4bfbf to your computer and use it in GitHub Desktop.
Hacking AWS API Gateway e AWS Lambda
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
| { | |
| "Version": "2012-10-17", | |
| "Statement": [ | |
| { | |
| "Effect": "Allow", | |
| "Resource": [ | |
| "*" | |
| ], | |
| "Action": [ | |
| "lambda:InvokeFunction" | |
| ] | |
| } | |
| ] | |
| } |
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
| (function () { | |
| //Todos os logs são enviados para o CloudWatch | |
| console.log('Loading function'); | |
| var AWS = require('aws-sdk'); | |
| AWS.config.region = 'us-east-1'; | |
| exports.handler = function(event, context) { | |
| console.log("Loading handler"); | |
| var sns = new AWS.SNS(); | |
| var topicArn = "{{o ARN do tópico SNS aqui}}"; | |
| var data = {}; | |
| data.createdAt = new Date().toJSON(); | |
| data.messageId = event.messageId; | |
| data.publisherId = event.publisherId; | |
| data.score = event.score; | |
| console.log("Data being sent to SNS:", data); | |
| sns.publish({ | |
| Message: JSON.stringify(data), | |
| TopicArn: topicArn | |
| }, function(err) { | |
| if (err) { | |
| context.fail(err.stack) | |
| } else { | |
| console.log('push sent'); | |
| context.succeed('Function Finished!'); | |
| } | |
| }); | |
| }; | |
| })() |
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
| { | |
| "Version": "2012-10-17", | |
| "Statement": [ | |
| { | |
| "Action": [ | |
| "logs:*" | |
| ], | |
| "Effect": "Allow", | |
| "Resource": "arn:aws:logs:*:*:*" | |
| } | |
| ] | |
| } |
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
| { | |
| "Version": "2012-10-17", | |
| "Statement": [ | |
| { | |
| "Effect": "Allow", | |
| "Action": [ | |
| "sns:Publish" | |
| ], | |
| "Resource": "{{ARN do seu tópico SNS aqui}}" | |
| } | |
| ] | |
| } |
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
| { | |
| "messageId": "$input.params('messageId')", | |
| "publisherId": "$input.params('publisherId')", | |
| "score": "$input.params('score')" | |
| } |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment