-
Notifications
You must be signed in to change notification settings - Fork 21
/
Copy pathtemplate.yml
73 lines (73 loc) · 2.33 KB
/
template.yml
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
AWSTemplateFormatVersion: 2010-09-09
Transform: AWS::Serverless-2016-10-31
Parameters:
TableName:
Type: String
Description: (Required) The name of the new DynamoDB table you want to create and save to. Minimum 3 characters
MinLength: 3
MaxLength: 50
AllowedPattern: ^[A-Za-z_]+$
ConstraintDescription: 'Required. Can be characters and underscore only. No numbers or special characters allowed.'
CorsOrigin:
Type: String
Default: "'*'"
Description: (Optional) Cross-origin resource sharing (CORS) Origin. You can specify a single origin, all "*" or leave empty and no CORS will be applied.
MaxLength: 250
Resources:
SaveApi:
Type: AWS::Serverless::Api
Properties:
Cors:
AllowHeaders: "'Content-Type,Authorization,X-Amz-Date,X-Api-Key,X-Amz-Security-Token'"
AllowOrigin: !Ref CorsOrigin
MaxAge: "'3600'"
AllowMethods: "'OPTIONS,POST'"
EndpointConfiguration: REGIONAL
TracingEnabled: true
StageName: prod
LambdaSaver:
Type: AWS::Serverless::Function
Properties:
Handler: index.handler
Runtime: nodejs12.x
CodeUri: src/
Environment:
Variables:
TABLE_NAME: !Ref TableName
CORS_ORIGIN: !Ref CorsOrigin
PRIMARY_KEY: !Sub ${TableName}Id
Policies:
- DynamoDBCrudPolicy:
TableName: !Ref TableName
Events:
SaveApi:
Type: Api
Properties:
Path: /save
Method: POST
RestApiId: !Ref SaveApi
DynamoDBTable:
Type: AWS::DynamoDB::Table
Properties:
TableName: !Ref TableName
AttributeDefinitions:
- AttributeName: !Sub ${TableName}Id
AttributeType: S
KeySchema:
- AttributeName: !Sub ${TableName}Id
KeyType: HASH
BillingMode: PAY_PER_REQUEST
SSESpecification:
SSEEnabled: True
StreamSpecification:
StreamViewType: NEW_IMAGE
Outputs:
ApiUrl:
Value: !Sub https://${SaveApi}.execute-api.${AWS::Region}.amazonaws.com/prod/save
Description: The URL of the API Gateway you invoke to save to your DynamoDB Table.
DynamoDBTable:
Value: !Ref TableName
Description: The name of your DynamoDB Table
DynamoDBTableStreamArn:
Value: !GetAtt DynamoDBTable.StreamArn
Description: The ARN of your DynamoDB Table Stream