-
Notifications
You must be signed in to change notification settings - Fork 94
/
Copy pathtemplate.yaml
282 lines (278 loc) · 9.67 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
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
# This is the SAM template that represents the architecture of your serverless application
# https://docs.aws.amazon.com/serverless-application-model/latest/developerguide/serverless-sam-template-basics.html
# The AWSTemplateFormatVersion identifies the capabilities of the template
# https://docs.aws.amazon.com/AWSCloudFormation/latest/UserGuide/format-version-structure.html
AWSTemplateFormatVersion: 2010-09-09
Description: >-
developer-sailpoint-site
# Transform section specifies one or more macros that AWS CloudFormation uses to process your template
# https://docs.aws.amazon.com/AWSCloudFormation/latest/UserGuide/transform-section-structure.html
Transform:
- AWS::Serverless-2016-10-31
# Resources declares the AWS resources that you want to include in the stack
# https://docs.aws.amazon.com/AWSCloudFormation/latest/UserGuide/resources-section-structure.html
Resources:
# Each Lambda function is defined by properties:
# https://github.com/awslabs/serverless-application-model/blob/master/versions/2016-10-31.md#awsserverlessfunction
# This is an API gateway associated with the developerSailpointGetByIdFunction and developerSailpointPutItemFunctions
MessageApiAuthRole:
Type: AWS::IAM::Role
Properties:
AssumeRolePolicyDocument:
Version: "2012-10-17"
Statement:
- Effect: "Allow"
Principal:
Service:
- "apigateway.amazonaws.com"
Action:
- sts:AssumeRole
Policies:
- PolicyName: "InvokeMessageAuthFunction"
PolicyDocument:
Version: "2012-10-17"
Statement:
- Effect: "Allow"
Action:
- lambda:InvokeAsync
- lambda:InvokeFunction
Resource: !GetAtt DeveloperSailpointAuthFunction.Arn
DeveloperSailpointApiGatewayApiv2:
Type: AWS::Serverless::HttpApi
Properties:
StageName: Prod
CorsConfiguration:
AllowMethods:
- "OPTIONS"
- "GET"
- "POST"
AllowHeaders:
- "Content-Type"
AllowOrigins:
- "https://developer.sailpoint.com"
DefaultRouteSettings:
DetailedMetricsEnabled: true
ThrottlingBurstLimit: 10
ThrottlingRateLimit: 5
Auth:
DefaultAuthorizer: LambdaAuthorizer
Authorizers:
LambdaAuthorizer:
FunctionPayloadType: REQUEST
FunctionArn: !GetAtt DeveloperSailpointAuthFunction.Arn
FunctionInvokeRole: !GetAtt MessageApiAuthRole.Arn
Identity:
Headers:
- Authorization
AuthorizerPayloadFormatVersion: "2.0"
EnableSimpleResponses: false
DeveloperSailpointAuthFunction:
Type: AWS::Serverless::Function
Properties:
Environment:
Variables:
AUTH_USERNAME: !Ref AuthUsername
AUTH_PASSWORD: !Ref AuthPassword
CodeUri: backend/src/auth/
Handler: index.authHandler
Runtime: nodejs18.x
Architectures:
- x86_64
MemorySize: 128
Timeout: 100
JSONPathGoFunction:
Type: AWS::Serverless::Function
Metadata:
BuildMethod: go1.x
Properties:
Handler: bootstrap
Runtime: provided.al2023
CodeUri: backend/src/go
MemorySize: 128
Timeout: 30
Events:
Api:
Type: HttpApi
Properties:
Path: /jsonpath/go
Method: POST
ApiId:
Ref: DeveloperSailpointApiGatewayApiv2
Auth:
Authorizer: NONE
JSONPathJavaFunction:
Type: AWS::Serverless::Function
Properties:
Handler: com.sailpoint.handler.JSONPathHandler::handleRequest
Runtime: java11
CodeUri: backend/src/java
MemorySize: 128
Timeout: 30
Events:
Api:
Type: HttpApi
Properties:
Path: /jsonpath/java
Method: POST
ApiId:
Ref: DeveloperSailpointApiGatewayApiv2
Auth:
Authorizer: NONE
# This is a Lambda function config associated with the source code: get-by-id.js
developerSailpointGetByIdFunction:
Type: AWS::Serverless::Function
Properties:
CodeUri: backend/src/handlers/
Handler: get-by-id.getByIdHandler
Runtime: nodejs18.x
Architectures:
- x86_64
MemorySize: 128
Timeout: 100
Description: A simple example includes a HTTP get method to get one item by id from a DynamoDB table.
Policies:
# Give Create/Read/Update/Delete Permissions to the CMSTable
- DynamoDBCrudPolicy:
TableName: !Ref CMSTable
Environment:
Variables:
# Make table name accessible as environment variable from function code during execution
SAMPLE_TABLE: !Ref CMSTable
# Make DynamoDB endpoint accessible as environment variable from function code during execution
ENDPOINT_OVERRIDE: ""
Events:
Api:
Type: HttpApi
Properties:
Path: /{id}
Method: GET
ApiId:
Ref: DeveloperSailpointApiGatewayApiv2
Auth:
Authorizer: NONE
# Each Lambda function is defined by properties:
# https://github.com/awslabs/serverless-application-model/blob/master/versions/2016-10-31.md#awsserverlessfunction
# DynamoDB table to store item: {id: <ID>, name: <NAME>}
CMSTable:
Type: AWS::Serverless::SimpleTable
Properties:
PrimaryKey:
Name: id
Type: String
ProvisionedThroughput:
ReadCapacityUnits: 20
WriteCapacityUnits: 2
# S3 Bucket to host single page app website
DeveloperSailpointWebSiteBucket:
Type: "AWS::S3::Bucket"
Properties:
BucketEncryption:
ServerSideEncryptionConfiguration:
- BucketKeyEnabled: true
WebsiteConfiguration:
IndexDocument: index.html
ErrorDocument: 404.html
PublicAccessBlockConfiguration:
BlockPublicAcls: false
BlockPublicPolicy: false
IgnorePublicAcls: false
RestrictPublicBuckets: false
DeveloperSailpointWebSiteBucketPolicy:
Type: "AWS::S3::BucketPolicy"
Properties:
Bucket: !Ref DeveloperSailpointWebSiteBucket
PolicyDocument:
Version: "2012-10-17"
Id: "PolicyForCloudFrontPrivateContent"
Statement:
- Sid: "AllowCloudFrontServicePrincipal"
Effect: "Allow"
Principal:
Service: "cloudfront.amazonaws.com"
Action: "s3:GetObject"
Resource: !Join [ "", [ "arn:aws:s3:::", !Ref DeveloperSailpointWebSiteBucket, "/*" ] ]
Condition:
StringEquals:
"AWS:SourceArn": !Join [ "", [ "arn:aws:cloudfront::", !Ref "AWS::AccountId", ":distribution/", !Ref DeveloperSailpointCloudFrontDistribution ] ]
- Sid: "PublicReadGetObject"
Effect: "Allow"
Principal: "*"
Action:
- "s3:GetObject"
Resource: !Join [ "", [ "arn:aws:s3:::", !Ref DeveloperSailpointWebSiteBucket, "/*" ] ]
# CloudFront Distribution for hosting the single page app website
DeveloperSailpointCloudFrontDistribution:
Type: "AWS::CloudFront::Distribution"
Properties:
DistributionConfig:
Origins:
- DomainName: !Join ["", [!Ref DeveloperSailpointWebSiteBucket, ".s3-website-", !Ref "AWS::Region", ".amazonaws.com"]]
Id: "DeveloperSailpointWebS3Origin"
CustomOriginConfig:
OriginProtocolPolicy: "http-only"
Enabled: true
DefaultRootObject: "index.html"
HttpVersion: "http2"
DefaultCacheBehavior:
AllowedMethods:
- "DELETE"
- "GET"
- "HEAD"
- "OPTIONS"
- "PATCH"
- "POST"
- "PUT"
CachedMethods:
- "GET"
- "HEAD"
TargetOriginId: "DeveloperSailpointWebS3Origin"
ForwardedValues:
QueryString: false
Cookies:
Forward: "none"
ViewerProtocolPolicy: "allow-all"
MinTTL: 0
DefaultTTL: 3600
MaxTTL: 86400
PriceClass: "PriceClass_200"
Restrictions:
GeoRestriction:
RestrictionType: "whitelist"
Locations:
- "US"
- "CA"
- "GB"
- "DE"
ViewerCertificate:
CloudFrontDefaultCertificate: true
CloudFrontOriginAccessControl:
Type: "AWS::CloudFront::OriginAccessControl"
Properties:
OriginAccessControlConfig:
Name: !Sub "${AWS::StackName}-OAC"
OriginAccessControlOriginType: "s3"
SigningBehavior: "always"
SigningProtocol: "sigv4"
Parameters:
AuthUsername:
Type: String
Description: Username for basic auth
AuthPassword:
Type: String
Description: Password for basic auth
Outputs:
DeveloperSailpointAPIGatewayEndpoint:
Description: "API Gateway endpoint URL for Prod stage"
Value: !Sub "https://${DeveloperSailpointApiGatewayApiv2}.execute-api.${AWS::Region}.amazonaws.com/Prod/"
DeveloperSailpointCloudFrontDistributionId:
Description: "CloudFront Distribution ID for hosting web front end"
Value: !Ref DeveloperSailpointCloudFrontDistribution
DeveloperSailpointCloudFrontDistributionDomainName:
Description: "CloudFront Distribution Domain Name for accessing web front end"
Value: !GetAtt DeveloperSailpointCloudFrontDistribution.DomainName
DeveloperSailpointWebS3BucketName:
Description: "S3 Bucket for hosting web frontend"
Value: !Ref DeveloperSailpointWebSiteBucket
ApiGatewayRestApiId:
Description: "API Gateway endpoint URL for Prod stage"
Value: !Ref DeveloperSailpointApiGatewayApiv2