-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathcloudFormationTemplate.yaml
More file actions
85 lines (85 loc) · 2.38 KB
/
cloudFormationTemplate.yaml
File metadata and controls
85 lines (85 loc) · 2.38 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
AWSTemplateFormatVersion: '2010-09-09'
Transform: AWS::Serverless-2016-10-31
Resources:
# API Gateway defined in a separate swagger document
ApiGatewayApi:
Type: AWS::Serverless::Api
Properties:
StageName: prod
DefinitionUri: swagger.yml
Variables:
# Stage variable needed in order to get the resulting name of the Lambda Function
# after deployment
LambdaFunctionName: !Ref LambdaFunction
# Lambda function definition
LambdaFunction:
Type: AWS::Serverless::Function
Properties:
Handler: built/api_backend.handler
Runtime: nodejs4.3
Policies: AmazonDynamoDBFullAccess
CodeUri: ./
Timeout: 10
Environment:
Variables:
# DynamoDB Table name is given to Lambda function as an environment variable
TABLE_NAME: !Ref DynamoDBTable
# These events will call the Lambda
Events:
ProxyApiRoot:
Type: Api
Properties:
Path: /
Method: ANY
RestApiId: !Ref ApiGatewayApi
ProxyApiGreedy:
Type: Api
Properties:
Path: /{proxy+}
Method: ANY
RestApiId: !Ref ApiGatewayApi
# Add necessary permissions for API Gateway to invoke Lambda function
Permission:
Type: AWS::Lambda::Permission
Properties:
FunctionName:
Fn::GetAtt:
- LambdaFunction
- Arn
Action: lambda:InvokeFunction
Principal: apigateway.amazonaws.com
SourceArn: !Join
- ''
- - 'arn:aws:execute-api:'
- !Ref AWS::Region
- ':'
- !Ref AWS::AccountId
- ':'
- !Ref ApiGatewayApi
- '/*/*/*'
# Defines a quite simple DynamoDB table
DynamoDBTable:
Type: AWS::DynamoDB::Table
Properties:
AttributeDefinitions:
- AttributeName: "timeFrom"
AttributeType: S
KeySchema:
- AttributeName: "timeFrom"
KeyType: HASH
ProvisionedThroughput:
ReadCapacityUnits: 5
WriteCapacityUnits: 5
TableName: "reservations"
# Outputs of this CloudFormation template
# Returns the resulting API Gateway endpoint URL
Outputs:
ApiUrl:
Description: URL of the API endpoint
Value: !Join
- ''
- - https://
- !Ref ApiGatewayApi
- '.execute-api.'
- !Ref 'AWS::Region'
- '.amazonaws.com/prod'