Add S3 putObject support
This commit is contained in:
parent
7a6a77ba2d
commit
f56fa787be
3 changed files with 126 additions and 3 deletions
22
README.md
22
README.md
|
@ -89,6 +89,28 @@ A JSON array of items to be inserted, in JSON format (not DynamoDB format).
|
||||||
DynamoDBPutItemsFunctionArn
|
DynamoDBPutItemsFunctionArn
|
||||||
|
|
||||||
|
|
||||||
|
### Put S3 Objects
|
||||||
|
|
||||||
|
Mirrors the S3.putObject API method (http://docs.aws.amazon.com/AWSJavaScriptSDK/latest/AWS/S3.html#putObject-property).
|
||||||
|
|
||||||
|
#### Parameters
|
||||||
|
|
||||||
|
##### Bucket
|
||||||
|
The S3 bucket to put the object into
|
||||||
|
|
||||||
|
##### Key
|
||||||
|
The name of the object. Can include a "path" for organization in S3.
|
||||||
|
|
||||||
|
##### Body
|
||||||
|
The content of the object being put into S3 (a string).
|
||||||
|
|
||||||
|
##### Other
|
||||||
|
Please see the reference above for further parameters - these are only the most commonly-used ones.
|
||||||
|
|
||||||
|
#### Reference Output Name
|
||||||
|
S3PutObjectFunctionArn
|
||||||
|
|
||||||
|
|
||||||
### Subscribe to SNS topics
|
### Subscribe to SNS topics
|
||||||
|
|
||||||
Mirrors the SNS.Subscribe API method (http://docs.aws.amazon.com/AWSJavaScriptSDK/latest/AWS/SNS.html#subscribe-property).
|
Mirrors the SNS.Subscribe API method (http://docs.aws.amazon.com/AWSJavaScriptSDK/latest/AWS/SNS.html#subscribe-property).
|
||||||
|
|
|
@ -1,7 +1,8 @@
|
||||||
var AWS = require('aws-sdk');
|
var AWS = require('aws-sdk');
|
||||||
var dynamoDB = new AWS.DynamoDB();
|
var dynamoDB = new AWS.DynamoDB(),
|
||||||
var response = require('./lib/cfn-response');
|
response = require('./lib/cfn-response'),
|
||||||
var sns = new AWS.SNS();
|
s3 = new AWS.S3(),
|
||||||
|
sns = new AWS.SNS();
|
||||||
|
|
||||||
exports.dynamoDBPutItems = function(event, context) {
|
exports.dynamoDBPutItems = function(event, context) {
|
||||||
var p = event.ResourceProperties;
|
var p = event.ResourceProperties;
|
||||||
|
@ -19,6 +20,33 @@ exports.dynamoDBPutItems = function(event, context) {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// Puts an object into S3.
|
||||||
|
exports.s3PutObject = function(event, context) {
|
||||||
|
var p = event.ResourceProperties;
|
||||||
|
if (event.RequestType == 'Delete') {
|
||||||
|
s3.deleteObject({
|
||||||
|
Bucket: p.Bucket,
|
||||||
|
Key: p.Key,
|
||||||
|
RequestPayer: p.RequestPayer
|
||||||
|
}, function(err, data) {
|
||||||
|
if (err) {
|
||||||
|
error(err, event, context);
|
||||||
|
} else {
|
||||||
|
response.send(event, context, response.SUCCESS);
|
||||||
|
}
|
||||||
|
});
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
s3.putObject(p, function(err, data) {
|
||||||
|
if (err) {
|
||||||
|
error(err, event, context);
|
||||||
|
} else {
|
||||||
|
response.send(event, context, response.SUCCESS, { "data": data });
|
||||||
|
}
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
// Exposes the SNS.subscribe API method
|
// Exposes the SNS.subscribe API method
|
||||||
exports.snsSubscribe = function(event, context) {
|
exports.snsSubscribe = function(event, context) {
|
||||||
const allowedProtocols = ['application', 'email', 'email-json', 'http', 'https', 'lambda', 'sms', 'sqs'];
|
const allowedProtocols = ['application', 'email', 'email-json', 'http', 'https', 'lambda', 'sms', 'sqs'];
|
||||||
|
|
|
@ -69,6 +69,75 @@
|
||||||
"DynamoDBPutItemsFunctionRole"
|
"DynamoDBPutItemsFunctionRole"
|
||||||
]
|
]
|
||||||
},
|
},
|
||||||
|
"S3PutObjectFunctionRole": {
|
||||||
|
"Type": "AWS::IAM::Role",
|
||||||
|
"Properties": {
|
||||||
|
"AssumeRolePolicyDocument": {
|
||||||
|
"Version" : "2012-10-17",
|
||||||
|
"Statement": [
|
||||||
|
{
|
||||||
|
"Effect": "Allow",
|
||||||
|
"Principal": {
|
||||||
|
"Service": [ "lambda.amazonaws.com" ]
|
||||||
|
},
|
||||||
|
"Action": [ "sts:AssumeRole" ]
|
||||||
|
}
|
||||||
|
]
|
||||||
|
},
|
||||||
|
"Policies": [
|
||||||
|
{
|
||||||
|
"PolicyName": "LogWriter",
|
||||||
|
"PolicyDocument": {
|
||||||
|
"Version" : "2012-10-17",
|
||||||
|
"Statement": [
|
||||||
|
{
|
||||||
|
"Effect": "Allow",
|
||||||
|
"Action": [
|
||||||
|
"logs:CreateLogGroup",
|
||||||
|
"logs:CreateLogStream",
|
||||||
|
"logs:PutLogEvents"
|
||||||
|
],
|
||||||
|
"Resource": "arn:aws:logs:*:*:*"
|
||||||
|
}
|
||||||
|
]
|
||||||
|
}
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"PolicyName": "S3Writer",
|
||||||
|
"PolicyDocument": {
|
||||||
|
"Version" : "2012-10-17",
|
||||||
|
"Statement": [
|
||||||
|
{
|
||||||
|
"Effect": "Allow",
|
||||||
|
"Action": [
|
||||||
|
"s3:DeleteObject",
|
||||||
|
"s3:PutObject"
|
||||||
|
],
|
||||||
|
"Resource": "*"
|
||||||
|
}
|
||||||
|
]
|
||||||
|
}
|
||||||
|
}
|
||||||
|
]
|
||||||
|
}
|
||||||
|
},
|
||||||
|
"S3PutObjectFunction": {
|
||||||
|
"Type": "AWS::Lambda::Function",
|
||||||
|
"Properties": {
|
||||||
|
"Code": {
|
||||||
|
"S3Bucket": "com.gilt.public.backoffice",
|
||||||
|
"S3Key": "lambda_functions/cloudformation-helpers.zip"
|
||||||
|
},
|
||||||
|
"Description": "Used to put objects into S3.",
|
||||||
|
"Handler": "cloudformation_helpers.s3PutObject",
|
||||||
|
"Role": {"Fn::GetAtt" : [ "S3PutObjectFunctionRole", "Arn" ] },
|
||||||
|
"Runtime": "nodejs",
|
||||||
|
"Timeout": 30
|
||||||
|
},
|
||||||
|
"DependsOn": [
|
||||||
|
"S3PutObjectFunctionRole"
|
||||||
|
]
|
||||||
|
},
|
||||||
"SnsSubscribeFunctionRole": {
|
"SnsSubscribeFunctionRole": {
|
||||||
"Type": "AWS::IAM::Role",
|
"Type": "AWS::IAM::Role",
|
||||||
"Properties": {
|
"Properties": {
|
||||||
|
@ -146,6 +215,10 @@
|
||||||
"SnsSubscribeFunctionArn": {
|
"SnsSubscribeFunctionArn": {
|
||||||
"Description": "The ARN of the SnsSubscribeFunction, for use in other CloudFormation templates.",
|
"Description": "The ARN of the SnsSubscribeFunction, for use in other CloudFormation templates.",
|
||||||
"Value": { "Fn::GetAtt" : ["SnsSubscribeFunction", "Arn"] }
|
"Value": { "Fn::GetAtt" : ["SnsSubscribeFunction", "Arn"] }
|
||||||
|
},
|
||||||
|
"S3PutObjectFunctionArn": {
|
||||||
|
"Description": "The ARN of the S3PutObjectFunction, for use in other CloudFormation templates.",
|
||||||
|
"Value": { "Fn::GetAtt" : ["S3PutObjectFunction", "Arn"] }
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
Loading…
Add table
Reference in a new issue