Created
June 3, 2021 09:09
-
-
Save afaquejam/92f3412f42ed178239c3f54f9df20c25 to your computer and use it in GitHub Desktop.
Example Service Cloudformation
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": "The AWS CloudFormation template for this Serverless application", | |
"Resources": { | |
"ServerlessDeploymentBucket": { | |
"Type": "AWS::S3::Bucket", | |
"Properties": { | |
"BucketEncryption": { | |
"ServerSideEncryptionConfiguration": [ | |
{ | |
"ServerSideEncryptionByDefault": { | |
"SSEAlgorithm": "AES256" | |
} | |
} | |
] | |
} | |
} | |
}, | |
"ServerlessDeploymentBucketPolicy": { | |
"Type": "AWS::S3::BucketPolicy", | |
"Properties": { | |
"Bucket": { | |
"Ref": "ServerlessDeploymentBucket" | |
}, | |
"PolicyDocument": { | |
"Statement": [ | |
{ | |
"Action": "s3:*", | |
"Effect": "Deny", | |
"Principal": "*", | |
"Resource": [ | |
{ | |
"Fn::Join": [ | |
"", | |
[ | |
"arn:", | |
{ | |
"Ref": "AWS::Partition" | |
}, | |
":s3:::", | |
{ | |
"Ref": "ServerlessDeploymentBucket" | |
}, | |
"/*" | |
] | |
] | |
}, | |
{ | |
"Fn::Join": [ | |
"", | |
[ | |
"arn:", | |
{ | |
"Ref": "AWS::Partition" | |
}, | |
":s3:::", | |
{ | |
"Ref": "ServerlessDeploymentBucket" | |
} | |
] | |
] | |
} | |
], | |
"Condition": { | |
"Bool": { | |
"aws:SecureTransport": false | |
} | |
} | |
} | |
] | |
} | |
} | |
}, | |
"CreateRestaurantsHandlerLogGroup": { | |
"Type": "AWS::Logs::LogGroup", | |
"Properties": { | |
"LogGroupName": "/aws/lambda/restaurants-service-dev-createRestaurantsHandler" | |
} | |
}, | |
"IamRoleLambdaExecution": { | |
"Type": "AWS::IAM::Role", | |
"Properties": { | |
"AssumeRolePolicyDocument": { | |
"Version": "2012-10-17", | |
"Statement": [ | |
{ | |
"Effect": "Allow", | |
"Principal": { | |
"Service": [ | |
"lambda.amazonaws.com" | |
] | |
}, | |
"Action": [ | |
"sts:AssumeRole" | |
] | |
} | |
] | |
}, | |
"Policies": [ | |
{ | |
"PolicyName": { | |
"Fn::Join": [ | |
"-", | |
[ | |
"restaurants-service", | |
"dev", | |
"lambda" | |
] | |
] | |
}, | |
"PolicyDocument": { | |
"Version": "2012-10-17", | |
"Statement": [ | |
{ | |
"Effect": "Allow", | |
"Action": [ | |
"logs:CreateLogStream", | |
"logs:CreateLogGroup" | |
], | |
"Resource": [ | |
{ | |
"Fn::Sub": "arn:${AWS::Partition}:logs:${AWS::Region}:${AWS::AccountId}:log-group:/aws/lambda/restaurants-service-dev*:*" | |
} | |
] | |
}, | |
{ | |
"Effect": "Allow", | |
"Action": [ | |
"logs:PutLogEvents" | |
], | |
"Resource": [ | |
{ | |
"Fn::Sub": "arn:${AWS::Partition}:logs:${AWS::Region}:${AWS::AccountId}:log-group:/aws/lambda/restaurants-service-dev*:*:*" | |
} | |
] | |
}, | |
{ | |
"Effect": "Allow", | |
"Action": [ | |
"dynamodb:PutItem" | |
], | |
"Resource": "arn:aws:dynamodb:*:*:table/solt-restaurants" | |
} | |
] | |
} | |
} | |
], | |
"Path": "/", | |
"RoleName": { | |
"Fn::Join": [ | |
"-", | |
[ | |
"restaurants-service", | |
"dev", | |
{ | |
"Ref": "AWS::Region" | |
}, | |
"lambdaRole" | |
] | |
] | |
} | |
} | |
}, | |
"CreateRestaurantsHandlerLambdaFunction": { | |
"Type": "AWS::Lambda::Function", | |
"Properties": { | |
"Code": { | |
"S3Bucket": { | |
"Ref": "ServerlessDeploymentBucket" | |
}, | |
"S3Key": "serverless/restaurants-service/dev/1622711300676-2021-06-03T09:08:20.676Z/restaurants-service.zip" | |
}, | |
"Handler": "handler.createRestaurantsHandler", | |
"Runtime": "nodejs12.x", | |
"FunctionName": "restaurants-service-dev-createRestaurantsHandler", | |
"MemorySize": 512, | |
"Timeout": 6, | |
"Role": { | |
"Fn::GetAtt": [ | |
"IamRoleLambdaExecution", | |
"Arn" | |
] | |
} | |
}, | |
"DependsOn": [ | |
"CreateRestaurantsHandlerLogGroup" | |
] | |
}, | |
"CreateRestaurantsHandlerLambdaVersiono8ksg5QzG02EbrJAPBdH1kGFPHObulQPgHwPKsnS6E": { | |
"Type": "AWS::Lambda::Version", | |
"DeletionPolicy": "Retain", | |
"Properties": { | |
"FunctionName": { | |
"Ref": "CreateRestaurantsHandlerLambdaFunction" | |
}, | |
"CodeSha256": "l1gVyPiSjXGxlkUPxJbterkUNGobobzGBbLQD1IPw6I=" | |
} | |
}, | |
"ApiGatewayRestApi": { | |
"Type": "AWS::ApiGateway::RestApi", | |
"Properties": { | |
"Name": "dev-restaurants-service", | |
"EndpointConfiguration": { | |
"Types": [ | |
"EDGE" | |
] | |
}, | |
"Policy": "" | |
} | |
}, | |
"ApiGatewayResourceRestaurants": { | |
"Type": "AWS::ApiGateway::Resource", | |
"Properties": { | |
"ParentId": { | |
"Fn::GetAtt": [ | |
"ApiGatewayRestApi", | |
"RootResourceId" | |
] | |
}, | |
"PathPart": "restaurants", | |
"RestApiId": { | |
"Ref": "ApiGatewayRestApi" | |
} | |
} | |
}, | |
"ApiGatewayMethodRestaurantsPost": { | |
"Type": "AWS::ApiGateway::Method", | |
"Properties": { | |
"HttpMethod": "POST", | |
"RequestParameters": {}, | |
"ResourceId": { | |
"Ref": "ApiGatewayResourceRestaurants" | |
}, | |
"RestApiId": { | |
"Ref": "ApiGatewayRestApi" | |
}, | |
"ApiKeyRequired": false, | |
"AuthorizationType": "NONE", | |
"Integration": { | |
"IntegrationHttpMethod": "POST", | |
"Type": "AWS_PROXY", | |
"Uri": { | |
"Fn::Join": [ | |
"", | |
[ | |
"arn:", | |
{ | |
"Ref": "AWS::Partition" | |
}, | |
":apigateway:", | |
{ | |
"Ref": "AWS::Region" | |
}, | |
":lambda:path/2015-03-31/functions/", | |
{ | |
"Fn::GetAtt": [ | |
"CreateRestaurantsHandlerLambdaFunction", | |
"Arn" | |
] | |
}, | |
"/invocations" | |
] | |
] | |
} | |
}, | |
"MethodResponses": [] | |
} | |
}, | |
"ApiGatewayDeployment1622711297237": { | |
"Type": "AWS::ApiGateway::Deployment", | |
"Properties": { | |
"RestApiId": { | |
"Ref": "ApiGatewayRestApi" | |
}, | |
"StageName": "dev" | |
}, | |
"DependsOn": [ | |
"ApiGatewayMethodRestaurantsPost" | |
] | |
}, | |
"CreateRestaurantsHandlerLambdaPermissionApiGateway": { | |
"Type": "AWS::Lambda::Permission", | |
"Properties": { | |
"FunctionName": { | |
"Fn::GetAtt": [ | |
"CreateRestaurantsHandlerLambdaFunction", | |
"Arn" | |
] | |
}, | |
"Action": "lambda:InvokeFunction", | |
"Principal": "apigateway.amazonaws.com", | |
"SourceArn": { | |
"Fn::Join": [ | |
"", | |
[ | |
"arn:", | |
{ | |
"Ref": "AWS::Partition" | |
}, | |
":execute-api:", | |
{ | |
"Ref": "AWS::Region" | |
}, | |
":", | |
{ | |
"Ref": "AWS::AccountId" | |
}, | |
":", | |
{ | |
"Ref": "ApiGatewayRestApi" | |
}, | |
"/*/*" | |
] | |
] | |
} | |
} | |
}, | |
"ShopsTable": { | |
"Type": "AWS::DynamoDB::Table", | |
"Properties": { | |
"TableName": "solt-restaurants", | |
"AttributeDefinitions": [ | |
{ | |
"AttributeName": "restaurantId", | |
"AttributeType": "S" | |
} | |
], | |
"KeySchema": [ | |
{ | |
"AttributeName": "restaurantId", | |
"KeyType": "HASH" | |
} | |
], | |
"BillingMode": "PAY_PER_REQUEST" | |
} | |
} | |
}, | |
"Outputs": { | |
"ServerlessDeploymentBucketName": { | |
"Value": { | |
"Ref": "ServerlessDeploymentBucket" | |
} | |
}, | |
"CreateRestaurantsHandlerLambdaFunctionQualifiedArn": { | |
"Description": "Current Lambda function version", | |
"Value": { | |
"Ref": "CreateRestaurantsHandlerLambdaVersiono8ksg5QzG02EbrJAPBdH1kGFPHObulQPgHwPKsnS6E" | |
} | |
}, | |
"ServiceEndpoint": { | |
"Description": "URL of the service endpoint", | |
"Value": { | |
"Fn::Join": [ | |
"", | |
[ | |
"https://", | |
{ | |
"Ref": "ApiGatewayRestApi" | |
}, | |
".execute-api.", | |
{ | |
"Ref": "AWS::Region" | |
}, | |
".", | |
{ | |
"Ref": "AWS::URLSuffix" | |
}, | |
"/dev" | |
] | |
] | |
} | |
} | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment