@@ -77,17 +77,34 @@ $ ./mvnw -ntp clean verify -U
7777 $ curl --location --request POST ' http://localhost:8080' \
7878 --header ' Content-Type: application/json' \
7979 --data-raw ' {
80- "body": "{ \"name\": \"CoffeeBeans\" }"
80+ "httpMethod": "POST",
81+ "body": "{ \"env\": \"production\", \"costCentre\": \"1234\", \"applicationName\": \"some-app\", \"items\": { \"GITHUB_TOKEN\": \"WOAH\", \"AWS_ACCESS_KEY_ID\": \"OMG\", \"AWS_SECRET_ACCESS_KEY\": \"OH NO\" } }"
8182 }'
8283 ` ` `
84+ ` ` ` shell
85+ curl --location --request POST ' http://localhost:8080' \
86+ --header ' Content-Type: application/json' \
87+ --data-raw ' {
88+ "httpMethod": "GET",
89+ "pathParameters": {
90+ "proxy": "production-1234-someapp"
91+ }
92+ }'
93+ ` ` `
94+
8395 The service responds
8496 ` ` ` json
85- [
86- {
87- " name" : " CoffeeBeans" ,
88- " saved" : true
89- }
90- ]
97+ {
98+ " id" : " production1234someapp" ,
99+ " env" : " production" ,
100+ " costCentre" : " 1234" ,
101+ " applicationName" : " some-app" ,
102+ " items" : {
103+ " GITHUB_TOKEN" : " WOAH" ,
104+ " AWS_ACCESS_KEY_ID" : " OMG" ,
105+ " AWS_SECRET_ACCESS_KEY" : " OH NO"
106+ }
107+ }
91108 ` ` `
92109
93110# ## Github action
@@ -150,67 +167,151 @@ and the following trust relationship
150167 " Version" : " 2012-10-17" ,
151168 " Statement" : [
152169 {
153- " Sid" : " ECRPermissions" ,
170+ " Sid" : " S3Permissions" ,
171+ " Effect" : " Allow" ,
172+ " Action" : " s3:GetObject" ,
173+ " Resource" : [
174+ " arn:aws:s3:::cdk-cbcore-assets-718055627712-ap-southeast-2" ,
175+ " arn:aws:s3:::cdk-cbcore-assets-718055627712-ap-southeast-2/*"
176+ ]
177+ },
178+ {
179+ " Sid" : " AGWPermissions" ,
154180 " Effect" : " Allow" ,
155181 " Action" : [
156- " ecr:CreateRepository" ,
157- " ecr:DeleteRepository" ,
158- " ecr:SetRepositoryPolicy" ,
159- " ecr:DescribeRepositories"
182+ " apigateway:POST" ,
183+ " apigateway:DELETE" ,
184+ " apigateway:GET" ,
185+ " apigateway:PATCH" ,
186+ " apigateway:PUT"
160187 ],
161- " Resource" : " arn:aws:ecr:{aws-region}:{aws-account-number}:repository/cdk-{qualifier}-container-assets-{aws-account-number}-{aws-region}"
188+ " Resource" : [
189+ " arn:aws:apigateway:ap-southeast-2::/restapis" ,
190+ " arn:aws:apigateway:ap-southeast-2::/restapis/*" ,
191+ " arn:aws:apigateway:ap-southeast-2::/account" ,
192+ " arn:aws:apigateway:ap-southeast-2::/tags/arn:aws:apigateway:ap-southeast-2::/restapis/*"
193+ ]
162194 },
163195 {
164- " Sid" : " IAMPermissions " ,
196+ " Sid" : " SNSPermissions " ,
165197 " Effect" : " Allow" ,
166198 " Action" : [
167- " iam:GetRole" ,
168- " iam:CreateRole" ,
169- " iam:DeleteRole" ,
170- " iam:AttachRolePolicy" ,
171- " iam:PutRolePolicy" ,
172- " iam:DetachRolePolicy" ,
173- " iam:DeleteRolePolicy"
199+ " SNS:CreateTopic" ,
200+ " SNS:DeleteTopic" ,
201+ " SNS:Subscribe" ,
202+ " SNS:GetTopicAttributes" ,
203+ " SNS:ListSubscriptionsByTopic" ,
204+ " SNS:Unsubscribe" ,
205+ " SNS:TagResource" ,
206+ " SNS:UntagResource"
174207 ],
175208 " Resource" : [
176- " arn:aws:iam::{aws-account-number}:role/cdk-{qualifier}-lookup-role-{aws-account-number}-{aws-region}" ,
177- " arn:aws:iam::{aws-account-number}:role/cdk-{qualifier}-file-publishing-role-{aws-account-number}-{aws-region}" ,
178- " arn:aws:iam::{aws-account-number}:role/cdk-{qualifier}-image-publishing-role-{aws-account-number}-{aws-region}" ,
179- " arn:aws:iam::{aws-account-number}:role/cdk-{qualifier}-cfn-exec-role-{aws-account-number}-{aws-region}" ,
180- " arn:aws:iam::{aws-account-number}:role/cdk-{qualifier}-deploy-role-{aws-account-number}-{aws-region}"
209+ " arn:aws:sqs:ap-southeast-2:718055627712:SpringNativeAwsFunctionStack-LambdaDeadLetterTopic*"
181210 ]
182211 },
183212 {
184- " Sid" : " S3Permissions " ,
213+ " Sid" : " SQSPermissions " ,
185214 " Effect" : " Allow" ,
186215 " Action" : [
187- " s3:PutBucketPublicAccessBlock" ,
188- " s3:CreateBucket" ,
189- " s3:DeleteBucketPolicy" ,
190- " s3:PutEncryptionConfiguration" ,
191- " s3:GetEncryptionConfiguration" ,
192- " s3:PutBucketPolicy" ,
193- " s3:DeleteBucket" ,
194- " s3:PutBucketVersioning"
216+ " sqs:GetQueueAttributes" ,
217+ " sqs:CreateQueue" ,
218+ " sqs:DeleteQueue" ,
219+ " sqs:GetQueueUrl" ,
220+ " sqs:SetQueueAttributes" ,
221+ " sqs:ListQueues"
195222 ],
196223 " Resource" : [
197- " arn:aws:s3:::{qualifier}-cdk-bucket"
224+ " arn:aws:sqs:ap-southeast-2:718055627712:SpringNativeAwsFunctionStack-LambdaDeadLetterQueue*"
225+ ]
226+ },
227+ {
228+ " Sid" : " LambdaPermissions" ,
229+ " Effect" : " Allow" ,
230+ " Action" : [
231+ " lambda:GetFunction" ,
232+ " lambda:ListFunctions" ,
233+ " lambda:DeleteFunction" ,
234+ " lambda:CreateFunction" ,
235+ " lambda:TagResource" ,
236+ " lambda:AddPermission" ,
237+ " lambda:RemovePermission" ,
238+ " lambda:PutFunctionEventInvokeConfig" ,
239+ " lambda:UpdateFunctionEventInvokeConfig" ,
240+ " lambda:DeleteFunctionEventInvokeConfig" ,
241+ " lambda:UpdateFunctionCode" ,
242+ " lambda:ListTags" ,
243+ " lambda:UpdateFunctionConfiguration"
244+ ],
245+ " Resource" : [
246+ " arn:aws:lambda:ap-southeast-2:718055627712:function:SpringNativeAwsFunctionStack*"
198247 ]
199248 },
200249 {
201250 " Sid" : " SSMPermissions" ,
202251 " Effect" : " Allow" ,
203252 " Action" : [
204- " ssm:DeleteParameter" ,
205- " ssm:AddTagsToResource" ,
206- " ssm:GetParameters" ,
207- " ssm:PutParameter"
253+ " ssm:GetParameters"
254+ ],
255+ " Resource" : [
256+ " arn:aws:ssm:ap-southeast-2:718055627712:parameter/cdk-bootstrap/cbcore/version"
257+ ]
258+ },
259+ {
260+ " Sid" : " DynamoDBPermissions" ,
261+ " Effect" : " Allow" ,
262+ " Action" : [
263+ " dynamodb:DescribeTable" ,
264+ " dynamodb:CreateTable" ,
265+ " dynamodb:DeleteTable" ,
266+ " dynamodb:TagResource" ,
267+ " dynamodb:UntagResource" ,
268+ " dynamodb:ListTagsOfResource" ,
269+ " dynamodb:DescribeTimeToLive" ,
270+ " dynamodb:DescribeContributorInsights" ,
271+ " dynamodb:DescribeContinuousBackups" ,
272+ " dynamodb:DescribeKinesisStreamingDestination"
273+ ],
274+ " Resource" : [
275+ " arn:aws:dynamodb:ap-southeast-2:718055627712:table/secrets" ,
276+ " arn:aws:dynamodb:ap-southeast-2:718055627712:table/SpringNativeAwsFunction*"
277+ ]
278+ },
279+ {
280+ " Sid" : " IAMPermissions" ,
281+ " Effect" : " Allow" ,
282+ " Action" : [
283+ " iam:PassRole" ,
284+ " iam:GetRole" ,
285+ " iam:GetRolePolicy" ,
286+ " iam:CreateRole" ,
287+ " iam:PutRolePolicy" ,
288+ " iam:DeleteRole" ,
289+ " iam:DeleteRolePolicy" ,
290+ " iam:AttachRolePolicy" ,
291+ " iam:DetachRolePolicy"
292+ ],
293+ " Resource" : [
294+ " arn:aws:iam::718055627712:role/SpringNativeAwsFunction*"
295+ ]
296+ },
297+ {
298+ " Sid" : " CFNPermissions" ,
299+ " Effect" : " Allow" ,
300+ " Action" : " cloudformation:DescribeStacks" ,
301+ " Resource" : " arn:aws:cloudformation:ap-southeast-2:718055627712:stack/cbcore-example-function-dev-stack/*"
302+ },
303+ {
304+ " Sid" : " ApplicationAutoscalingPermissions" ,
305+ " Effect" : " Allow" ,
306+ " Action" : [
307+ " application-autoscaling:DeregisterScalableTarget"
208308 ],
209- " Resource" : " arn:aws:ssm:{aws-region}:{aws-account-number}:parameter/cdk-bootstrap/{qualifier}/version"
309+ " Resource" : [
310+ " arn:aws:application-autoscaling:ap-southeast-2:718055627712:scalable-target/*"
311+ ]
210312 }
211313 ]
212- }
213- ` ` `
314+ }` ` `
214315
2153164. Create an IAM managed policy ` CoffeebeansCoreCdkExecutionAccess` to be used
216317 by ` cdk-{qualifier}-cfn-exec-role-{aws-account-number}-{aws-region}` which is gonna be created by
@@ -351,16 +452,18 @@ Now that the setup is done you can deploy to AWS.
351452 environment.
3524532. Test via curl
353454 ` ` ` shell
354- $ curl --location --request POST ' https://{api-id}.execute-api.ap-southeast-2.amazonaws.com/dev/name' \
355- --header ' Content-Type: application/json' \
356- --data-raw ' {
357- "name": "CoffeeBeans"
455+ $ curl --location --request POST ' https://lmk0qo0xrl.execute-api.ap-southeast-2.amazonaws.com/dev/' \
456+ --header ' Content-Type: application/json' \
457+ --data-raw ' {
458+ "env": "production",
459+ "costCentre": "1234",
460+ "applicationName": "some-app",
461+ "items": {
462+ "GITHUB_TOKEN": "WOAH",
463+ "AWS_ACCESS_KEY_ID": "OMG",
464+ "AWS_SECRET_ACCESS_KEY": "OH NO"
465+ }
358466 }'
359467 ` ` `
3604683. Et voila! It runs with 500 ms for cold start.
361-
362- ` ` ` shell
363- curl --location --request POST ' https://lmk0qo0xrl.execute-api.ap-southeast-2.amazonaws.com/dev/
364- --header ' Content-Type: application/json' \
365- --data-raw ' { " env" : " production" , " costCentre" : " 1234" , " applicationName" : " some-app" , " items" : [ { " key" : " GITHUB_TOKEN" , " value" : " WOAH" }, { " key" : " AWS_ACCESS_KEY_ID" , " value" : " OMG" }, { " key" : " AWS_SECRET_ACCESS_KEY" , " value" : " OH, NO" } ] }'
366- ```
469+
0 commit comments