Skip to content

Commit fb7a498

Browse files
committed
Renaming some modules
1 parent 4ffa483 commit fb7a498

File tree

3 files changed

+147
-54
lines changed

3 files changed

+147
-54
lines changed

README.md

Lines changed: 144 additions & 53 deletions
Original file line numberDiff line numberDiff line change
@@ -77,17 +77,22 @@ $ ./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+
"body": "{ \"env\": \"production\", \"costCentre\": \"1234\", \"applicationName\": \"some-app\", \"items\": { \"GITHUB_TOKEN\": \"WOAH\", \"AWS_ACCESS_KEY_ID\": \"OMG\", \"AWS_SECRET_ACCESS_KEY\": \"OH NO\" } }"
8181
}'
8282
```
8383
The service responds
8484
```json
85-
[
86-
{
87-
"name": "CoffeeBeans",
88-
"saved": true
89-
}
90-
]
85+
{
86+
"id": "production1234someapp",
87+
"env": "production",
88+
"costCentre": "1234",
89+
"applicationName": "some-app",
90+
"items": {
91+
"GITHUB_TOKEN": "WOAH",
92+
"AWS_ACCESS_KEY_ID": "OMG",
93+
"AWS_SECRET_ACCESS_KEY": "OH NO"
94+
}
95+
}
9196
```
9297

9398
### Github action
@@ -150,67 +155,151 @@ and the following trust relationship
150155
"Version": "2012-10-17",
151156
"Statement": [
152157
{
153-
"Sid": "ECRPermissions",
158+
"Sid": "S3Permissions",
159+
"Effect": "Allow",
160+
"Action": "s3:GetObject",
161+
"Resource": [
162+
"arn:aws:s3:::cdk-cbcore-assets-718055627712-ap-southeast-2",
163+
"arn:aws:s3:::cdk-cbcore-assets-718055627712-ap-southeast-2/*"
164+
]
165+
},
166+
{
167+
"Sid": "AGWPermissions",
154168
"Effect": "Allow",
155169
"Action": [
156-
"ecr:CreateRepository",
157-
"ecr:DeleteRepository",
158-
"ecr:SetRepositoryPolicy",
159-
"ecr:DescribeRepositories"
170+
"apigateway:POST",
171+
"apigateway:DELETE",
172+
"apigateway:GET",
173+
"apigateway:PATCH",
174+
"apigateway:PUT"
160175
],
161-
"Resource": "arn:aws:ecr:{aws-region}:{aws-account-number}:repository/cdk-{qualifier}-container-assets-{aws-account-number}-{aws-region}"
176+
"Resource": [
177+
"arn:aws:apigateway:ap-southeast-2::/restapis",
178+
"arn:aws:apigateway:ap-southeast-2::/restapis/*",
179+
"arn:aws:apigateway:ap-southeast-2::/account",
180+
"arn:aws:apigateway:ap-southeast-2::/tags/arn:aws:apigateway:ap-southeast-2::/restapis/*"
181+
]
162182
},
163183
{
164-
"Sid": "IAMPermissions",
184+
"Sid": "SNSPermissions",
165185
"Effect": "Allow",
166186
"Action": [
167-
"iam:GetRole",
168-
"iam:CreateRole",
169-
"iam:DeleteRole",
170-
"iam:AttachRolePolicy",
171-
"iam:PutRolePolicy",
172-
"iam:DetachRolePolicy",
173-
"iam:DeleteRolePolicy"
187+
"SNS:CreateTopic",
188+
"SNS:DeleteTopic",
189+
"SNS:Subscribe",
190+
"SNS:GetTopicAttributes",
191+
"SNS:ListSubscriptionsByTopic",
192+
"SNS:Unsubscribe",
193+
"SNS:TagResource",
194+
"SNS:UntagResource"
174195
],
175196
"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}"
197+
"arn:aws:sqs:ap-southeast-2:718055627712:SpringNativeAwsFunctionStack-LambdaDeadLetterTopic*"
181198
]
182199
},
183200
{
184-
"Sid": "S3Permissions",
201+
"Sid": "SQSPermissions",
185202
"Effect": "Allow",
186203
"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"
204+
"sqs:GetQueueAttributes",
205+
"sqs:CreateQueue",
206+
"sqs:DeleteQueue",
207+
"sqs:GetQueueUrl",
208+
"sqs:SetQueueAttributes",
209+
"sqs:ListQueues"
195210
],
196211
"Resource": [
197-
"arn:aws:s3:::{qualifier}-cdk-bucket"
212+
"arn:aws:sqs:ap-southeast-2:718055627712:SpringNativeAwsFunctionStack-LambdaDeadLetterQueue*"
213+
]
214+
},
215+
{
216+
"Sid": "LambdaPermissions",
217+
"Effect": "Allow",
218+
"Action": [
219+
"lambda:GetFunction",
220+
"lambda:ListFunctions",
221+
"lambda:DeleteFunction",
222+
"lambda:CreateFunction",
223+
"lambda:TagResource",
224+
"lambda:AddPermission",
225+
"lambda:RemovePermission",
226+
"lambda:PutFunctionEventInvokeConfig",
227+
"lambda:UpdateFunctionEventInvokeConfig",
228+
"lambda:DeleteFunctionEventInvokeConfig",
229+
"lambda:UpdateFunctionCode",
230+
"lambda:ListTags",
231+
"lambda:UpdateFunctionConfiguration"
232+
],
233+
"Resource": [
234+
"arn:aws:lambda:ap-southeast-2:718055627712:function:SpringNativeAwsFunctionStack*"
198235
]
199236
},
200237
{
201238
"Sid": "SSMPermissions",
202239
"Effect": "Allow",
203240
"Action": [
204-
"ssm:DeleteParameter",
205-
"ssm:AddTagsToResource",
206-
"ssm:GetParameters",
207-
"ssm:PutParameter"
241+
"ssm:GetParameters"
242+
],
243+
"Resource": [
244+
"arn:aws:ssm:ap-southeast-2:718055627712:parameter/cdk-bootstrap/cbcore/version"
245+
]
246+
},
247+
{
248+
"Sid": "DynamoDBPermissions",
249+
"Effect": "Allow",
250+
"Action": [
251+
"dynamodb:DescribeTable",
252+
"dynamodb:CreateTable",
253+
"dynamodb:DeleteTable",
254+
"dynamodb:TagResource",
255+
"dynamodb:UntagResource",
256+
"dynamodb:ListTagsOfResource",
257+
"dynamodb:DescribeTimeToLive",
258+
"dynamodb:DescribeContributorInsights",
259+
"dynamodb:DescribeContinuousBackups",
260+
"dynamodb:DescribeKinesisStreamingDestination"
208261
],
209-
"Resource": "arn:aws:ssm:{aws-region}:{aws-account-number}:parameter/cdk-bootstrap/{qualifier}/version"
262+
"Resource": [
263+
"arn:aws:dynamodb:ap-southeast-2:718055627712:table/secrets",
264+
"arn:aws:dynamodb:ap-southeast-2:718055627712:table/SpringNativeAwsFunction*"
265+
]
266+
},
267+
{
268+
"Sid": "IAMPermissions",
269+
"Effect": "Allow",
270+
"Action": [
271+
"iam:PassRole",
272+
"iam:GetRole",
273+
"iam:GetRolePolicy",
274+
"iam:CreateRole",
275+
"iam:PutRolePolicy",
276+
"iam:DeleteRole",
277+
"iam:DeleteRolePolicy",
278+
"iam:AttachRolePolicy",
279+
"iam:DetachRolePolicy"
280+
],
281+
"Resource": [
282+
"arn:aws:iam::718055627712:role/SpringNativeAwsFunction*"
283+
]
284+
},
285+
{
286+
"Sid": "CFNPermissions",
287+
"Effect": "Allow",
288+
"Action": "cloudformation:DescribeStacks",
289+
"Resource": "arn:aws:cloudformation:ap-southeast-2:718055627712:stack/cbcore-example-function-dev-stack/*"
290+
},
291+
{
292+
"Sid": "ApplicationAutoscalingPermissions",
293+
"Effect": "Allow",
294+
"Action": [
295+
"application-autoscaling:DeregisterScalableTarget"
296+
],
297+
"Resource": [
298+
"arn:aws:application-autoscaling:ap-southeast-2:718055627712:scalable-target/*"
299+
]
210300
}
211301
]
212-
}
213-
```
302+
}```
214303

215304
4. Create an IAM managed policy `CoffeebeansCoreCdkExecutionAccess` to be used
216305
by `cdk-{qualifier}-cfn-exec-role-{aws-account-number}-{aws-region}` which is gonna be created by
@@ -351,16 +440,18 @@ Now that the setup is done you can deploy to AWS.
351440
environment.
352441
2. Test via curl
353442
```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"
443+
$ curl --location --request POST 'https://lmk0qo0xrl.execute-api.ap-southeast-2.amazonaws.com/dev/' \
444+
--header 'Content-Type: application/json' \
445+
--data-raw '{
446+
"env": "production",
447+
"costCentre": "1234",
448+
"applicationName": "some-app",
449+
"items": {
450+
"GITHUB_TOKEN": "WOAH",
451+
"AWS_ACCESS_KEY_ID": "OMG",
452+
"AWS_SECRET_ACCESS_KEY": "OH NO"
453+
}
358454
}'
359455
```
360456
3. 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-
```
457+

spring-native-aws-service-infra/src/main/java/com/coffeebeans/springnativeawslambda/infra/Application.java

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -37,6 +37,8 @@
3737
public final class Application extends AbstractApp {
3838
private static final String ENVIRONMENT_NAME_DEV = "dev";
3939
private static final String ENVIRONMENT_NAME_PRD = "prd";
40+
41+
4042
private static final String LAMBDA_CODE_PATH = "spring-native-aws-service/target/spring-native-aws-service-native-zip.zip";
4143

4244
public static void main(final String... args) {

spring-native-aws-service/src/assembly/native.xml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -40,7 +40,7 @@
4040
<useDefaultExcludes>true</useDefaultExcludes>
4141
<fileMode>0775</fileMode>
4242
<includes>
43-
<include>spring-native-aws-function</include>
43+
<include>spring-native-aws-service</include>
4444
</includes>
4545
</fileSet>
4646
</fileSets>

0 commit comments

Comments
 (0)