-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathtemplate.yaml
200 lines (192 loc) · 6.74 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
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
AWSTemplateFormatVersion: '2010-09-09'
Transform: AWS::Serverless-2016-10-31
Description: >
sam-app
Sample SAM Template for sam-app
# More info about Globals: https://github.com/awslabs/serverless-application-model/blob/master/docs/globals.rst
Globals:
Function:
Timeout: 3
Runtime: python3.9
Architectures:
- x86_64
Environment:
Variables:
STAGE_PREFIX : !Ref StagePrefix
Parameters:
PaymentDomainHostedZoneId:
Type: "String"
Default: "Z03959971PI6LXD3U3GYA"
PaymentDomainName:
Type: "String"
Default: test.payment.jvmperformance.pl
PaymentCertificateArn:
Type: "String"
Default: "arn:aws:acm:eu-central-1:653932013369:certificate/7db121b9-b404-4af6-ad99-e972da300996"
Stage:
Type: "String"
Default: "test"
AllowedValues:
- "test"
- "prod"
StagePrefix:
Type: "String"
Default: "test."
AllowedValues:
- "test."
- "prod."
Parameters:
PaymentDomainHostedZoneId:
Type: "String"
Default: "Z03959971PI6LXD3U3GYA"
PaymentDomainName:
Type: "String"
Default: payment.jvmperformance.pl
PaymentCertificateArn:
Type: "String"
Default: "arn:aws:acm:us-east-1:653932013369:certificate/7923cd5a-f722-4591-88d6-4d0b20845c85"
Resources:
PaymentFunction:
Type: AWS::Serverless::Function # More info about Function Resource: https://github.com/awslabs/serverless-application-model/blob/master/versions/2016-10-31.md#awsserverlessfunction
Properties:
CodeUri: payment/
Handler: app.lambda_handler
Policies:
- DynamoDBCrudPolicy:
TableName: !Ref CourseTable
- DynamoDBCrudPolicy:
TableName: !Ref DiscountTable
Events:
Payment:
Type: Api # More info about API Event Source: https://github.com/awslabs/serverless-application-model/blob/master/versions/2016-10-31.md#api
Properties:
Path: /payment
Method: get
RestApiId: !Ref PaymentApiGateway
RestApiId: !Ref PaymentApiGateway
ConfirmationFunction:
Type: AWS::Serverless::Function # More info about Function Resource: https://github.com/awslabs/serverless-application-model/blob/master/versions/2016-10-31.md#awsserverlessfunction
Properties:
CodeUri: confirmation/
Handler: app.lambda_handler
Policies:
- DynamoDBCrudPolicy:
TableName: !Ref PaymentTable
- DynamoDBCrudPolicy:
TableName: !Ref CourseTable
- AWSSecretsManagerGetSecretValuePolicy:
SecretArn: "arn:aws:secretsmanager:eu-central-1:653932013369:secret:send-grid-api-key-mBgWr8"
Events:
Confirmation:
Type: Api # More info about API Event Source: https://github.com/awslabs/serverless-application-model/blob/master/versions/2016-10-31.md#api
Properties:
Path: /confirmation
Method: post
RestApiId: !Ref PaymentApiGateway
CoursesFunction:
Type: AWS::Serverless::Function # More info about Function Resource: https://github.com/awslabs/serverless-application-model/blob/master/versions/2016-10-31.md#awsserverlessfunction
Properties:
CodeUri: courses/
Handler: app.lambda_handler
Policies:
- DynamoDBCrudPolicy:
TableName: !Ref CourseTable
Events:
Confirmation:
Type: Api # More info about API Event Source: https://github.com/awslabs/serverless-application-model/blob/master/versions/2016-10-31.md#api
Properties:
Path: /courses
Method: get
RestApiId: !Ref PaymentApiGateway
PaymentTable:
Type: AWS::DynamoDB::Table
Properties:
TableName: !Join ['',[!Ref StagePrefix,"payments"]]
BillingMode: PAY_PER_REQUEST
AttributeDefinitions:
- AttributeName: id
AttributeType: S
KeySchema:
- AttributeName: id
KeyType: HASH
CourseTable:
Type: AWS::DynamoDB::Table
Properties:
TableName: !Join ['',[!Ref StagePrefix,"courses"]]
BillingMode: PAY_PER_REQUEST
AttributeDefinitions:
- AttributeName: course_name
AttributeType: S
- AttributeName: course_site
AttributeType: S
KeySchema:
- AttributeName: course_name
KeyType: HASH
GlobalSecondaryIndexes:
- IndexName: course_site_index
KeySchema:
- AttributeName: course_site
KeyType: HASH
Projection:
ProjectionType: INCLUDE
NonKeyAttributes: ["course_name","location","location_url","date","amount","is_active"]
DiscountTable:
Type: AWS::DynamoDB::Table
Properties:
TableName: !Join ['',[!Ref StagePrefix,"discounts"]]
BillingMode: PAY_PER_REQUEST
AttributeDefinitions:
- AttributeName: discount_code
AttributeType: S
KeySchema:
- AttributeName: discount_code
KeyType: HASH
ApiGwAccountConfig:
Type: "AWS::ApiGateway::Account"
Properties:
CloudWatchRoleArn: !GetAtt "ApiGatewayLoggingRole.Arn"
ApiGatewayLoggingRole:
Type: "AWS::IAM::Role"
Properties:
AssumeRolePolicyDocument:
Version: "2012-10-17"
Statement:
- Effect: Allow
Principal:
Service:
- "apigateway.amazonaws.com"
Action: "sts:AssumeRole"
Path: "/"
ManagedPolicyArns:
- !Sub "arn:${AWS::Partition}:iam::aws:policy/service-role/AmazonAPIGatewayPushToCloudWatchLogs"
PaymentGatewayLogGroup:
Type: AWS::Logs::LogGroup
Properties:
RetentionInDays: 14
PaymentApiGateway:
Type: AWS::Serverless::Api
Properties:
AccessLogSetting:
DestinationArn: !GetAtt PaymentGatewayLogGroup.Arn
Format: $context.identity.sourceIp $context.identity.caller $context.identity.user [$context.requestTime] "$context.httpMethod $context.resourcePath $context.protocol" $context.status $context.responseLength $context.requestId $context.extendedRequestId
StageName: !Ref Stage
Domain:
CertificateArn: !Ref PaymentCertificateArn
DomainName: !Ref PaymentDomainName
Route53:
HostedZoneId: !Ref PaymentDomainHostedZoneId
DependsOn: ["ApiGwAccountConfig"]
PaymentApiGateway:
Type: AWS::Serverless::Api
Properties:
StageName: prod
Domain:
CertificateArn: !Ref PaymentCertificateArn
DomainName: !Ref PaymentDomainName
Route53:
HostedZoneId: !Ref PaymentDomainHostedZoneId
HostedZoneName: !Ref PaymentDomainName
Outputs:
PaymentGatewayApi:
Description: "API Gateway endpoint URL for Prod stage for Hello World function"
Value: !Sub "https://${PaymentApiGateway}.execute-api.${AWS::Region}.amazonaws.com/Prod/payment/"