-
Notifications
You must be signed in to change notification settings - Fork 1
/
template.yaml
82 lines (73 loc) · 1.94 KB
/
template.yaml
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
AWSTemplateFormatVersion: '2010-09-09'
Transform: AWS::Serverless-2016-10-31
Description: >
DevOps SAM Template for aws-serverless-devops
Parameters:
Environment:
Type: String
AllowedValues:
- stage
- prod
Conditions:
ProdCondition:
!Equals [!Ref Environment, prod]
Globals:
Function:
Runtime: nodejs12.x
Tracing: Active
MemorySize: 128
Timeout: 100
Resources:
ServerlessHTTPApi:
Type: AWS::Serverless::HttpApi
Properties:
StageName: !Sub "${Environment}"
GetMyDataFunction:
Type: AWS::Serverless::Function
Properties:
FunctionName: !Sub "${AWS::StackName}-getMyDataFunction"
CodeUri: src/handlers/get-data/
Handler: app.lambdaHandler
Events:
HelloWorld:
Type: HttpApi
Properties:
ApiId: !Ref ServerlessHTTPApi
Path: /data
Method: get
SaveMyDataFunction:
Type: AWS::Serverless::Function
Properties:
FunctionName: !Sub "${AWS::StackName}-saveMyDataFunction"
CodeUri: src/handlers/save-data/
Handler: app.lambdaHandler
Policies:
- DynamoDBCrudPolicy:
TableName: !Ref MySimpleTableDB
Environment:
Variables:
DATA_TABLE: !Ref MySimpleTableDB
Events:
HelloWorld:
Type: HttpApi
Properties:
ApiId: !Ref ServerlessHTTPApi
Path: /data
Method: post
MySimpleTableDB:
Type: AWS::Serverless::SimpleTable
Properties:
TableName: !Sub "my-data-${Environment}"
PrimaryKey:
Name: id
Type: String
ProvisionedThroughput:
ReadCapacityUnits: 2
WriteCapacityUnits: 2
Outputs:
DataApi:
Description: "API Gateway endpoint URL for Prod stage for Hello World function"
Value: !Join
- ''
- - !Sub "https://${ServerlessHTTPApi}.execute-api.${AWS::Region}.amazonaws.com/"
- !If [ProdCondition, "prod", "stage"]