-
Notifications
You must be signed in to change notification settings - Fork 8
/
Copy pathtemplate.yaml
186 lines (166 loc) · 5.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
AWSTemplateFormatVersion: '2010-09-09'
Transform: AWS::Serverless-2016-10-31
Description: >
AWS Lambda SpringBoot 3.4 Lambda Web Adapter
Sample SAM Template
Parameters:
Stage:
Type: String
Default: prod
Globals:
Function:
Handler: run.sh
CodeUri: target/aws-lambda-spring-boot-3.4-lambda-web-adapter-1.0.0-SNAPSHOT.jar
Runtime: java21
Timeout: 30
MemorySize: 1024
SnapStart:
ApplyOn: PublishedVersions
Environment:
Variables:
JAVA_TOOL_OPTIONS: "-XX:+TieredCompilation -XX:TieredStopAtLevel=1"
PRODUCT_TABLE_NAME: !Ref ProductsTable
RUST_LOG: info
REMOVE_BASE_PATH: /v1
AWS_LAMBDA_EXEC_WRAPPER: /opt/bootstrap
Resources:
MyApi:
Type: AWS::Serverless::Api
DependsOn: MyApiCWLRoleArn
Properties:
StageName: !Ref Stage
Name: AWSLambdaSpringBoot34LambdaWebAdapterAPI
Description: Product API using AWS Lambda Spring Boot 3.4.Lambda Web Adapter
AccessLogSetting:
DestinationArn: !Sub ${MyApiLogGroup.Arn} # This Log Group is already created within our SAM Template
Format: "{'integrationLatency':'$context.integrationLatency', 'latency':'$context.responseLatency', 'requestId':'$context.requestId', 'ip': '$context.identity.sourceIp', 'caller':'$context.identity.caller', 'user':'$context.identity.user','requestTime':'$context.requestTime', 'xrayTraceId':'$context.xrayTraceId', 'wafResponseCode':'$context.wafResponseCode', 'httpMethod':'$context.httpMethod','resourcePath':'$context.resourcePath', 'status':'$context.status','protocol':'$context.protocol', 'responseLength':'$context.responseLength' }"
#MethodSettings:
# - MetricsEnabled: True
# ResourcePath: '/*'
# HttpMethod: '*'
Auth:
ApiKeyRequired: true # sets for all methods
MyApiCWLRoleArn:
Type: AWS::ApiGateway::Account
Properties:
CloudWatchRoleArn: !GetAtt CloudWatchRole.Arn
# IAM Role for API GW + CWL
CloudWatchRole:
Type: AWS::IAM::Role
Properties:
AssumeRolePolicyDocument:
Version: '2012-10-17'
Statement:
Action: 'sts:AssumeRole'
Effect: Allow
Principal:
Service: apigateway.amazonaws.com
Path: /
ManagedPolicyArns:
- 'arn:aws:iam::aws:policy/service-role/AmazonAPIGatewayPushToCloudWatchLogs'
MyApiLogGroup:
Type: AWS::Logs::LogGroup
Properties:
LogGroupName: !Sub "/aws/apigateway/${MyApi}"
RetentionInDays: 7
MyApiUsagePlan:
Type: AWS::ApiGateway::UsagePlan
DependsOn:
- MyApiStage
Properties:
ApiStages:
- ApiId: !Ref MyApi
Stage: !Ref Stage
UsagePlanName: AWSLambdaSpringBoot34LambdaWebAdapterAPIUsagePlan
Description: Usage plan for AWSLambdaSpringBoot34LambdaWebAdapterAPI
Quota:
Limit: 2000000
Period: DAY
Throttle:
RateLimit: 10000
BurstLimit: 50000
MyApiKey:
Type: AWS::ApiGateway::ApiKey
DependsOn:
- MyApiStage
Properties:
Name: "AWSLambdaSpringBoot34LambdaWebAdapterApiKey"
Description: "AWSLambdaSpringBoot34LambdaWebAdapter API Key"
Enabled: true
GenerateDistinctId: false
Value: a6ZbcDefQW12BN56WED34
StageKeys:
- RestApiId: !Ref MyApi
StageName: !Ref Stage
MyApiUsagePlanKey:
Type: "AWS::ApiGateway::UsagePlanKey"
DependsOn:
- MyApi
Properties:
KeyId: !Ref MyApiKey
KeyType: API_KEY
UsagePlanId: !Ref MyApiUsagePlan
GetProductByIdFunction:
Type: AWS::Serverless::Function
Properties:
FunctionName: GetProductByIdWithSpringBoot34WithLambdaWebAdapter
AutoPublishAlias: liveVersion
Layers:
- !Sub arn:aws:lambda:${AWS::Region}:753240598075:layer:LambdaAdapterLayerX86:23
Policies:
- DynamoDBReadPolicy:
TableName: !Ref ProductsTable
Events:
GetRequestById:
Type: Api
Properties:
RestApiId: !Ref MyApi
Path: /v1/products/{id}
Method: get
GetProductByIdFunctionLogGroup:
Type: AWS::Logs::LogGroup
Properties:
LogGroupName: !Sub "/aws/lambda/${GetProductByIdFunction}"
RetentionInDays: 7
PutProductFunction:
Type: AWS::Serverless::Function
Properties:
FunctionName: PutProductWithSpringBoot34WithLambdaWebAdapter
AutoPublishAlias: liveVersion
Layers:
- !Sub arn:aws:lambda:${AWS::Region}:753240598075:layer:LambdaAdapterLayerX86:23
Policies:
- DynamoDBCrudPolicy:
TableName: !Ref ProductsTable
Events:
PutRequest:
Type: Api
Properties:
RestApiId: !Ref MyApi
Path: /v1/products
Method: put
PutProductFunctionLogGroup:
Type: AWS::Logs::LogGroup
Properties:
LogGroupName: !Sub "/aws/lambda/${PutProductFunction}"
RetentionInDays: 7
ProductsTable:
Type: AWS::DynamoDB::Table
Properties:
TableName: "AWSLambdaSpringBoot34WithLambdaWebAdapterProductsTable"
PointInTimeRecoverySpecification:
PointInTimeRecoveryEnabled: true
AttributeDefinitions:
- AttributeName: 'PK'
AttributeType: 'S'
KeySchema:
- AttributeName: 'PK'
KeyType: 'HASH'
BillingMode: PAY_PER_REQUEST
#ProvisionedThroughput:
#ReadCapacityUnits: "1"
#WriteCapacityUnits: "1"
Outputs:
AWSLambdaSpringBoot34WithLambdaWebAdapterApiEndpoint:
Description: "API Gateway endpoint URL for Prod stage for AWS Lambda Spring Boot 3.4 Lambda Web Adapter"
Value: !Sub "https://${MyApi}.execute-api.${AWS::Region}.amazonaws.com/prod/products"