Skip to content

Instantly share code, notes, and snippets.

@linyatis
Created May 30, 2016 20:07
Show Gist options
  • Select an option

  • Save linyatis/d684cff4ff8e02972d53ae87b5c4bfbf to your computer and use it in GitHub Desktop.

Select an option

Save linyatis/d684cff4ff8e02972d53ae87b5c4bfbf to your computer and use it in GitHub Desktop.
Hacking AWS API Gateway e AWS Lambda
{
"Version": "2012-10-17",
"Statement": [
{
"Effect": "Allow",
"Resource": [
"*"
],
"Action": [
"lambda:InvokeFunction"
]
}
]
}
(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!');
}
});
};
})()
{
"Version": "2012-10-17",
"Statement": [
{
"Action": [
"logs:*"
],
"Effect": "Allow",
"Resource": "arn:aws:logs:*:*:*"
}
]
}
{
"Version": "2012-10-17",
"Statement": [
{
"Effect": "Allow",
"Action": [
"sns:Publish"
],
"Resource": "{{ARN do seu tópico SNS aqui}}"
}
]
}
{
"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