This file contains 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
AWSTemplateFormatVersion: 2010-09-09 | |
Description: CloudFormation template for a S3 bucket | |
Resources: | |
MyS3Bucket: | |
Type: AWS::S3::Bucket | |
Properties: | |
BucketName: i-named-this-bucket-1337 | |
MyLambda: | |
Type: AWS::Lambda::Function | |
Properties: | |
FunctionName: "my-function" | |
Handler: index.handler | |
Code: | |
ZipFile: | | |
var AWS = require("aws-sdk"); | |
var s3 = new AWS.S3(); | |
exports.handler = function(event, context) { | |
s3.listObjects({ Bucket: process.env.S3_BUCKET}, | |
function (err, data) { | |
if (err) throw err; | |
console.log(data) | |
}) | |
console.log("I'm a lambda!") | |
}; | |
Runtime: nodejs14.x | |
Role: !GetAtt LambdaExecutionRole.Arn | |
Environment: | |
Variables: | |
S3_BUCKET: !Ref MyS3Bucket | |
LambdaExecutionRole: | |
Type: AWS::IAM::Role | |
Properties: | |
AssumeRolePolicyDocument: | |
Version: '2012-10-17' | |
Statement: | |
- Effect: Allow | |
Principal: | |
Service: | |
- lambda.amazonaws.com | |
Action: | |
- sts:AssumeRole | |
Path: "/" | |
Policies: | |
- PolicyName: root | |
PolicyDocument: | |
Version: '2012-10-17' | |
Statement: | |
- Effect: Allow | |
Action: | |
- logs:* | |
Resource: arn:aws:logs:*:*:* | |
- PolicyName: list-s3 | |
PolicyDocument: | |
Version: '2012-10-17' | |
Statement: | |
- Effect: Allow | |
Action: | |
- s3:List* | |
Resource: !GetAtt MyS3Bucket.Arn |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment