-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathtemplate.yaml
More file actions
165 lines (155 loc) · 5.98 KB
/
template.yaml
File metadata and controls
165 lines (155 loc) · 5.98 KB
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
AWSTemplateFormatVersion: '2010-09-09'
Transform: AWS::Serverless-2016-10-31
Description: >
SponsorService
Sample SAM Template for SponsorService
Parameters:
Stage:
Type: String
Default: 'dev'
Description: either "prod" or "dev" determines which secrets and configs to deploy
Globals:
Function:
Timeout: 20
Resources:
MyApi:
Type: AWS::Serverless::Api
Properties:
Name: !Sub 'test-sponsors-api-${Stage}'
StageName: Prod
EndpointConfiguration: REGIONAL
# This turns on X-Ray tracing. For more details, see https://meetup.atlassian.net/wiki/spaces/CP/pages/854098408/DIY+Edge+API+Operations#DIYEdgeAPIOperations-Instrumentation
TracingEnabled: true
MinimumCompressionSize: 0
MethodSettings:
- ResourcePath: '/*'
HttpMethod: '*'
MetricsEnabled: 'true'
DefinitionBody:
swagger: 2.0
info:
title: !Sub "${AWS::StackName}"
version: 1.0
paths:
/sponsors:
get:
x-amazon-apigateway-integration:
uri: !Sub "arn:aws:apigateway:${AWS::Region}:lambda:path/2015-03-31/functions/${GetSponsorsFunction.Arn}/invocations"
passthroughBehavior: "when_no_match"
httpMethod: "POST"
type: "aws_proxy"
/sponsors/{id}:
get:
x-amazon-apigateway-integration:
uri: !Sub "arn:aws:apigateway:${AWS::Region}:lambda:path/2015-03-31/functions/${FindSponsorFunction.Arn}/invocations"
passthroughBehavior: "when_no_match"
httpMethod: "POST"
type: "aws_proxy"
x-amazon-apigateway-request-validators:
ValidateBody:
validateRequestParameters: false
validateRequestBody: true
LambdaFunctionRole:
Type: AWS::IAM::Role
Properties:
AssumeRolePolicyDocument:
Version: "2012-10-17"
Statement:
- Effect: "Allow"
Principal:
Service:
- "lambda.amazonaws.com"
- "edgelambda.amazonaws.com"
Action:
- "sts:AssumeRole"
ManagedPolicyArns:
- arn:aws:iam::aws:policy/service-role/AWSLambdaBasicExecutionRole
Policies:
- PolicyName: !Sub ${AWS::StackName}-lambda-policy
PolicyDocument:
Version: "2012-10-17"
Statement:
- Effect: Allow
Action:
- "dynamodb:DescribeTable"
- "dynamodb:Scan"
- "dynamodb:GetItem"
- "dynamodb:Query"
- "dynamodb:BatchGetItem"
- "dynamodb:BatchWriteItem"
- "dynamodb:PutItem"
- "dynamodb:UpdateItem"
- "dynamodb:DeleteItem"
- "ec2:CreateNetworkInterface"
- "ec2:DescribeNetworkInterfaces"
- "ec2:DeleteNetworkInterface"
- "sqs:ReceiveMessage"
- "sqs:SendMessage"
- "sqs:DeleteMessage"
- "sqs:GetQueueAttributes"
- "sqs:GetQueueUrl"
- "sqs:ChangeMessageVisibility"
- "sqs:SetQueueAttributes"
Resource: "*"
GetSponsorsFunction:
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:
FunctionName: !Sub 'test-java-lambda-get-sponsors-${Stage}'
CodeUri: build/libs/SponsorService-all.jar
Handler: com.test.handlers.GetSponsorsHandler::handleRequest
Runtime: java11
Role: !GetAtt LambdaFunctionRole.Arn
MemorySize: 512
Environment: # More info about Env Vars: https://github.com/awslabs/serverless-application-model/blob/master/versions/2016-10-31.md#environment-object
Variables:
PARAM1: VALUE
Events:
MyApi:
Type: Api # More info about API Event Source: https://github.com/awslabs/serverless-application-model/blob/master/versions/2016-10-31.md#api
Properties:
RestApiId: !Ref MyApi
Path: /sponsors
Method: get
GetSponsorsFunctionLogGroup:
Type: AWS::Logs::LogGroup
DependsOn: [ GetSponsorsFunction ]
Properties:
LogGroupName: !Sub /aws/lambda/${GetSponsorsFunction}
RetentionInDays: 60
FindSponsorFunction:
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:
FunctionName: !Sub 'test-java-lambda-find-sponsor-${Stage}'
CodeUri: build/libs/SponsorService-all.jar
Handler: com.test.handlers.FindSponsorHandler::handleRequest
Runtime: java11
MemorySize: 512
Role: !GetAtt LambdaFunctionRole.Arn
Environment: # More info about Env Vars: https://github.com/awslabs/serverless-application-model/blob/master/versions/2016-10-31.md#environment-object
Variables:
PARAM1: VALUE
Events:
MyApi:
Type: Api # More info about API Event Source: https://github.com/awslabs/serverless-application-model/blob/master/versions/2016-10-31.md#api
Properties:
RestApiId: !Ref MyApi
Path: /sponsors/{id}
Method: get
FindSponsorFunctionLogGroup:
Type: AWS::Logs::LogGroup
DependsOn: [ FindSponsorFunction ]
Properties:
LogGroupName: !Sub /aws/lambda/${FindSponsorFunction}
RetentionInDays: 60
Outputs:
ApiId:
Description: the unique ID associated with the API Gateway
Value: !Ref MyApi
Export:
Name: !Sub "${AWS::StackName}-ApiId"
GetSponsorsFunction:
Description: "Get sponsors Lambda Function ARN"
Value: !GetAtt GetSponsorsFunction.Arn
FindSponsorFunction:
Description: "Find sponsor Lambda Function ARN"
Value: !GetAtt FindSponsorFunction.Arn