-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathci-template.yml
More file actions
656 lines (649 loc) · 25.8 KB
/
ci-template.yml
File metadata and controls
656 lines (649 loc) · 25.8 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
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
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
AWSTemplateFormatVersion: 2010-09-09
# SAM (Serverless Application Model) transform enables shorthand syntax
# like AWS::Serverless::Function that CloudFormation expands into full resource definitions.
Transform: AWS::Serverless-2016-10-31
Description: CICD for the Benchmark Game AppSync/Rust lambda demo
Parameters:
ProjectName:
Type: String
Description: Name of the project to insert in all resources names
Default: "benchmark-game"
# Regex constraint: enforces DNS-safe naming (lowercase, no leading/trailing dash)
AllowedPattern: ^[a-z][a-z0-9-]{1,23}[a-z0-9]$
ConstraintDescription: Must be 3-25 characters, only lowercase letters, numbers and dashes, must not begin with a number or dash, must not end with a dash
# CodeStar Connections provides OAuth access to GitHub repos without storing credentials.
CodeStarConnectionArn:
Type: String
Description: The ARN of the CodeStart connection to GitHub, follow the Get Started on https://github.com/RustyServerless/benchmark-game.git
ForkedRepoId:
Type: String
Description: The ID of the FORKED repository in YOUR GitHub account, probably <YourGithubUserName>/benchmark-game
BranchName:
Type: String
Description: The name of the branch to track
Default: "master"
# Metadata > Interface customizes how parameters appear in the AWS Console deploy UI.
# Purely cosmetic, no runtime effect.
Metadata:
AWS::CloudFormation::Interface:
ParameterGroups:
- Label:
default: Repository connection
Parameters:
- CodeStarConnectionArn
- ForkedRepoId
- BranchName
- Label:
default: Project
Parameters:
- ProjectName
ParameterLabels:
ProjectName:
default: Name
CodeStarConnectionArn:
default: CodeStar Connection ARN
ForkedRepoId:
default: Repository Id
BranchName:
default: Branch Name
Resources:
#############
# Artifacts #
#############
ArtifactBucket:
Type: AWS::S3::Bucket
Properties:
# !Sub with pseudo-parameters (${AWS::AccountId}, ${AWS::Region}) creates a globally unique bucket name.
# S3 bucket names must be globally unique across ALL AWS accounts.
BucketName: !Sub ${ProjectName}-${AWS::AccountId}-${AWS::Region}-artifact
# Disables ACLs: all objects are owned by the bucket owner (modern S3 best practice)
OwnershipControls:
Rules:
- ObjectOwnership: BucketOwnerEnforced
# Defense-in-depth: blocks all public access paths to the bucket
PublicAccessBlockConfiguration:
BlockPublicAcls: true
BlockPublicPolicy: true
IgnorePublicAcls: true
RestrictPublicBuckets: true
# Lifecycle rules automatically manage object retention and storage class
LifecycleConfiguration:
Rules:
- Id: DeletePipelineArtifactsAfter1Day
Status: Enabled
Prefix: release-
ExpirationInDays: 1
- Id: DeleteOldVersionAfter1Day
Status: Enabled
NoncurrentVersionExpiration:
NoncurrentDays: 1
ExpiredObjectDeleteMarker: true
AbortIncompleteMultipartUpload:
DaysAfterInitiation: 1
- Id: TransitToIT
Status: Enabled
Transitions:
- TransitionInDays: 0
StorageClass: INTELLIGENT_TIERING
# CloudFormation Custom Resource: invokes a Lambda during stack lifecycle events.
# Here, it empties the S3 bucket on stack deletion (S3 buckets must be empty before CF can delete them).
ArtifactBucketEmptier:
Type: Custom::BucketEmptier
# DependsOn ensures the Lambda and its permissions exist before CF invokes the custom resource
DependsOn:
- BucketEmptierLambdaRole
- BucketEmptierLambdaRoleBasicPolicy
- BucketEmptierLambdaWorkPolicy
- BucketEmptierLambdaLogGroup
Properties:
# ServiceToken tells CloudFormation which Lambda ARN to invoke for this custom resource
ServiceToken: !GetAtt BucketEmptierLambda.Arn
BucketName: !Ref ArtifactBucket
# SAM shorthand for a Lambda function. InlineCode embeds the handler directly in the template.
BucketEmptierLambda:
Type: AWS::Serverless::Function
Properties:
FunctionName: !Sub ${ProjectName}-s3-bucket-emptier
Description: Called by a CF Custom Resource to empty an S3 bucket before destroying it
Handler: index.lambda_handler
Runtime: python3.13
MemorySize: 128
Architectures:
- arm64
# The handler checks event['RequestType']: on 'Delete', empties all object versions from the bucket.
# On 'Create'/'Update', does nothing. cfnresponse.send() signals success/failure back to CloudFormation.
InlineCode: |
import boto3
import cfnresponse
def lambda_handler(event, context):
try:
bucket_name = event['ResourceProperties']['BucketName']
physical_id = f"EMPTIER_{bucket_name}"
if event['RequestType'] == 'Delete':
bucket = boto3.resource('s3').Bucket(bucket_name)
bucket.object_versions.delete()
cfnresponse.send(event, context, cfnresponse.SUCCESS, {}, physical_id)
except Exception as e:
cfnresponse.send(event, context, cfnresponse.FAILED, {'Data': str(e)}, physical_id)
Timeout: 900 # 15 minutes — max Lambda timeout; emptying a large versioned bucket can be slow
Role: !GetAtt BucketEmptierLambdaRole.Arn
BucketEmptierLambdaLogGroup:
Type: AWS::Logs::LogGroup
Properties:
LogGroupName: !Sub /aws/lambda/${BucketEmptierLambda}
RetentionInDays: 90
# IAM Role with a trust policy allowing only lambda.amazonaws.com to assume it.
# This is the standard pattern for Lambda execution roles.
BucketEmptierLambdaRole:
Type: AWS::IAM::Role
Properties:
RoleName: !Sub ${ProjectName}-s3-bucket-emptier
# The "trust policy" defines WHO can assume this role.
# sts:AssumeRole with Principal: Service: lambda.amazonaws.com = only the Lambda service.
AssumeRolePolicyDocument:
Version: 2012-10-17
Statement:
- Effect: Allow
Principal:
Service: lambda.amazonaws.com
Action: sts:AssumeRole
Path: /
# Minimal CloudWatch Logs permissions so the Lambda can write its execution logs
BucketEmptierLambdaRoleBasicPolicy:
Type: AWS::IAM::Policy
Properties:
Roles:
- !Ref BucketEmptierLambdaRole
PolicyName: basic-lambda
PolicyDocument:
Version: 2012-10-17
Statement:
- Effect: Allow
Action:
- logs:CreateLogStream
- logs:PutLogEvents
Resource: !GetAtt BucketEmptierLambdaLogGroup.Arn
# S3 delete/list permissions for both the artifact and website buckets (the ones to empty on teardown).
# ${AWS::Partition} resolves to "aws" in standard regions, "aws-cn" in China, "aws-us-gov" in GovCloud.
BucketEmptierLambdaWorkPolicy:
Type: AWS::IAM::Policy
Properties:
Roles:
- !Ref BucketEmptierLambdaRole
PolicyName: work-rights
PolicyDocument:
Version: 2012-10-17
Statement:
- Effect: Allow
Action:
- s3:DeleteObject
- s3:DeleteObjectVersion
- s3:ListBucket
- s3:ListBucketVersions
Resource:
- !Sub arn:${AWS::Partition}:s3:::${ProjectName}-${AWS::AccountId}-${AWS::Region}-artifact
- !Sub arn:${AWS::Partition}:s3:::${ProjectName}-${AWS::AccountId}-${AWS::Region}-artifact/*
- !Sub arn:${AWS::Partition}:s3:::${ProjectName}-${AWS::AccountId}-${AWS::Region}-website
- !Sub arn:${AWS::Partition}:s3:::${ProjectName}-${AWS::AccountId}-${AWS::Region}-website/*
###############
# Build Infra #
###############
# CodeBuild project that compiles Rust lambdas and packages CloudFormation templates.
InfraBuildProject:
Type: AWS::CodeBuild::Project
DependsOn:
- ArtifactBucketEmptier
- InfraBuildProjectLogGroup
Properties:
Name: !Sub ${ProjectName}-infra-builder
Description: !Sub Project building infra for the project ${ProjectName}
ServiceRole: !GetAtt BuildProjectsRole.Arn
Environment:
# ARM_CONTAINER + BUILD_GENERAL1_SMALL runs on ARM64 (Graviton) for cost/performance.
Type: ARM_CONTAINER
ComputeType: BUILD_GENERAL1_SMALL
Image: aws/codebuild/amazonlinux-aarch64-standard:3.0
EnvironmentVariables:
- Name: ARTIFACT_BUCKET
Value: !Ref ArtifactBucket
Source:
# Source comes from CodePipeline (not directly from a repo)
Type: CODEPIPELINE
# BuildSpec path is relative to the source artifact root
BuildSpec: ./ci-config/buildspec.yml
Artifacts:
Type: CODEPIPELINE
# S3 cache: persists compiled Rust dependencies between builds to speed up subsequent builds
Cache:
Type: S3
Location: !Sub ${ArtifactBucket}/codebuildcache/${ProjectName}-infra-builder
TimeoutInMinutes: 60
Tags:
- Key: Name
Value: !Sub ${ProjectName}-infra-builder
InfraBuildProjectLogGroup:
Type: AWS::Logs::LogGroup
Properties:
LogGroupName: !Sub /aws/codebuild/${ProjectName}-infra-builder
RetentionInDays: 14
#################
# Build Website #
#################
WebsiteBuildProject:
Type: AWS::CodeBuild::Project
DependsOn:
- ArtifactBucketEmptier
- WebsiteBuildProjectLogGroup
Properties:
Name: !Sub ${ProjectName}-website-builder
Description: !Sub Project compiling static website for the project ${ProjectName}
ServiceRole: !GetAtt BuildProjectsRole.Arn
Environment:
Type: ARM_CONTAINER
ComputeType: BUILD_GENERAL1_SMALL
Image: aws/codebuild/amazonlinux-aarch64-standard:3.0
Source:
Type: CODEPIPELINE
BuildSpec: ./buildspec.yml
Artifacts:
Type: CODEPIPELINE
TimeoutInMinutes: 30
Tags:
- Key: Name
Value: !Sub ${ProjectName}-website-builder
WebsiteBuildProjectLogGroup:
Type: AWS::Logs::LogGroup
Properties:
LogGroupName: !Sub /aws/codebuild/${ProjectName}-website-builder
RetentionInDays: 14
# Shared IAM role for both CodeBuild projects — avoids duplicating purely technical common permissions
BuildProjectsRole:
Type: AWS::IAM::Role
Properties:
RoleName: !Sub ${ProjectName}-codebuild
AssumeRolePolicyDocument:
Version: 2012-10-17
Statement:
- Effect: Allow
Principal:
Service: codebuild.amazonaws.com
Action: sts:AssumeRole
Path: /
BuildProjectsRolePolicy:
Type: AWS::IAM::Policy
Properties:
Roles:
- !Ref BuildProjectsRole
PolicyName: policy-codebuild
PolicyDocument:
Version: 2012-10-17
Statement:
- Effect: Allow
Action: codestar-connections:UseConnection
Resource: !Ref CodeStarConnectionArn
- Effect: Allow
Action:
- s3:PutObject
- s3:GetObject
- s3:DeleteObject
- s3:ListBucket
Resource:
- !Sub arn:${AWS::Partition}:s3:::${ArtifactBucket}
- !Sub arn:${AWS::Partition}:s3:::${ArtifactBucket}/*
- Effect: Allow
Action:
- logs:CreateLogStream
- logs:PutLogEvents
Resource:
- !GetAtt InfraBuildProjectLogGroup.Arn
- !GetAtt WebsiteBuildProjectLogGroup.Arn
############
# Pipeline #
############
PipelineRole:
Type: AWS::IAM::Role
Properties:
RoleName: !Sub ${ProjectName}-codepipeline
AssumeRolePolicyDocument:
Version: 2012-10-17
Statement:
- Effect: Allow
Principal:
Service: codepipeline.amazonaws.com
Action: sts:AssumeRole
Policies:
- PolicyName: policy-codepipeline
PolicyDocument:
Version: 2012-10-17
Statement:
- Effect: Allow
Action: codestar-connections:UseConnection
Resource: !Ref CodeStarConnectionArn
- Effect: Allow
Action:
- codepipeline:*
- iam:ListRoles
- codebuild:BatchGetBuilds
- codebuild:StartBuild
- cloudformation:Describe*
- cloudFormation:List*
- cloudformation:CreateStack
- cloudformation:DeleteStack
- cloudformation:DescribeStacks
- cloudformation:UpdateStack
- cloudformation:CreateChangeSet
- cloudformation:DeleteChangeSet
- cloudformation:DescribeChangeSet
- cloudformation:ExecuteChangeSet
- cloudformation:SetStackPolicy
- cloudformation:ValidateTemplate
Resource: "*"
- Effect: Allow
Action:
- s3:PutObject
- s3:GetObject
- s3:ListBucket
Resource:
- !Sub arn:${AWS::Partition}:s3:::${ArtifactBucket}
- !Sub arn:${AWS::Partition}:s3:::${ArtifactBucket}/*
- !Sub arn:${AWS::Partition}:s3:::${ProjectName}-${AWS::AccountId}-${AWS::Region}-website/*
# iam:PassRole lets the pipeline hand off CFDeployerRole to CloudFormation.
# The condition restricts this to only the CloudFormation service (least privilege).
- Effect: Allow
Action: iam:PassRole
Resource: "*"
Condition:
StringEqualsIfExists:
"iam:PassedToService":
- cloudformation.amazonaws.com
Path: /
Pipeline:
Type: AWS::CodePipeline::Pipeline
DependsOn:
- ArtifactBucketEmptier
- BuildProjectsRolePolicy
Properties:
Name: !Sub release-${ProjectName}
RoleArn: !GetAtt PipelineRole.Arn
# V2 pipelines support namespaces, per-action pricing, and improved performance
PipelineType: V2
Stages:
- Name: Source
Actions:
- Name: Checkout
ActionTypeId:
Category: Source
Owner: AWS
Version: 1
Provider: CodeStarSourceConnection
Configuration:
ConnectionArn: !Ref CodeStarConnectionArn
FullRepositoryId: !Ref ForkedRepoId
BranchName: !Ref BranchName
# Triggers the pipeline automatically on new commits
DetectChanges: true
# CODEBUILD_CLONE_REF preserves full git history (not just a source zip)
OutputArtifactFormat: CODEBUILD_CLONE_REF
OutputArtifacts:
- Name: Sources
RunOrder: 1
- Name: BuildInfra
Actions:
- Name: BuildInfra
ActionTypeId:
Category: Build
Owner: AWS
Version: 1
Provider: CodeBuild
Configuration:
ProjectName: !Ref InfraBuildProject
RunOrder: 1
InputArtifacts:
- Name: Sources
# One CodeBuild action produces TWO output artifacts:
# - Infra: packaged CloudFormation templates
# - Website: website source code for the next build stage
# See ci-config/buildspec.yml
OutputArtifacts:
- Name: Infra
- Name: Website
- Name: DeployInfra
Actions:
- Name: DeployInfra
ActionTypeId:
Category: Deploy
Owner: AWS
Version: 1
Provider: CloudFormation
Configuration:
ChangeSetName: Deploy
# CREATE_UPDATE: creates the stack if new, updates if it exists
ActionMode: CREATE_UPDATE
StackName: !Sub ${ProjectName}-root
# Acknowledges that the template creates named IAM resources and uses transforms (SAM)
Capabilities: CAPABILITY_NAMED_IAM,CAPABILITY_AUTO_EXPAND
# CloudFormation writes stack outputs (API URL, Cognito IDs, etc.) to this JSON file.
# The website build stage reads it to inject env vars.
OutputFileName: infra.outputs.json
TemplatePath: Infra::root-template.yml
# Passes the CI stack's ProjectName parameter to the deployed root stack
ParameterOverrides: !Sub '{"ProjectName": "${ProjectName}"}'
RoleArn: !GetAtt CFDeployerRole.Arn
InputArtifacts:
- Name: Infra
OutputArtifacts:
- Name: DeployInfraOutput
RunOrder: 1
- Name: BuildWebsite
Actions:
- Name: BuildWebsite
# Namespace exports env vars that later stages reference with #{BuildWebsite.VAR_NAME}
Namespace: BuildWebsite
ActionTypeId:
Category: Build
Owner: AWS
Version: 1
Provider: CodeBuild
Configuration:
ProjectName: !Ref WebsiteBuildProject
# PrimarySource tells CodeBuild which input artifact contains the buildspec
PrimarySource: Website
RunOrder: 1
InputArtifacts:
- Name: Website
- Name: DeployInfraOutput
OutputArtifacts:
- Name: StaticContent
- Name: DynamicContent
# Two parallel S3 deploy actions with different cache strategies:
# Static content (JS/CSS/images) gets long cache headers (immutable)
# Dynamic content (HTML) gets short cache headers (must-revalidate)
- Name: DeployWebsite
Actions:
- Name: DeployStaticWebsite
ActionTypeId:
Category: Deploy
Owner: AWS
Version: 1
Provider: S3
Configuration:
# Pipeline variable syntax #{namespace.variable}: resolved at runtime from BuildWebsite stage
BucketName: "#{BuildWebsite.STATIC_WEB_BUCKET}"
Extract: true
CacheControl: public, max-age=604800, immutable
InputArtifacts:
- Name: StaticContent
RunOrder: 1
- Name: DeployDynamicWebsite
ActionTypeId:
Category: Deploy
Owner: AWS
Version: 1
Provider: S3
Configuration:
BucketName: "#{BuildWebsite.STATIC_WEB_BUCKET}"
Extract: true
CacheControl: public, max-age=300, must-revalidate
InputArtifacts:
- Name: DynamicContent
RunOrder: 1
ArtifactStore:
Type: S3
Location: !Ref ArtifactBucket
##################################
# CloudFormation deployment role #
##################################
CFDeployerRole:
Type: AWS::IAM::Role
Properties:
RoleName: !Sub ${ProjectName}-cf-deployer
AssumeRolePolicyDocument:
Version: 2012-10-17
Statement:
- Effect: Allow
Principal:
Service: cloudformation.amazonaws.com
Action: sts:AssumeRole
# NOTE ON ACTION WILDCARDS:
# Most statements below use "<service>:*" for actions, which looks broad
# but is actually scoped by the Resource ARN. IAM evaluates BOTH the action
# and the resource: an action will only be allowed if it matches the
# Resource ARN pattern too. For example, "s3:*" on a bucket ARN (without
# "/*") will never grant object-level operations like s3:GetObject, because
# those require an object ARN. This lets us keep the policy readable while
# still fairly restricting what the role can actually do.
# IAM is the exception: see the comment on IamRoles below.
Policies:
- PolicyName: !Sub ${ProjectName}-deployer
PolicyDocument:
Version: 2012-10-17
Statement:
##########################
# Artifacts & CloudFormation
##########################
- Sid: ReadArtifacts
Effect: Allow
Action: s3:GetObject
Resource: !Sub arn:${AWS::Partition}:s3:::${ArtifactBucket}/*
- Sid: CloudFormationChangeSet
Effect: Allow
Action: cloudformation:CreateChangeSet
Resource: "*"
- Sid: CloudFormationStacks
Effect: Allow
Action:
- cloudformation:DescribeStacks
- cloudformation:CreateStack
- cloudformation:UpdateStack
- cloudformation:RollbackStack
- cloudformation:DeleteStack
Resource: !Sub arn:${AWS::Partition}:cloudformation:${AWS::Region}:${AWS::AccountId}:stack/${ProjectName}-root*
# Allows CloudFormation to pass its OWN role to nested stacks.
# Without this, nested stack creation fails because CF can't delegate its own role.
- Sid: PassSelfRole
Effect: Allow
Action: iam:PassRole
Resource: !Sub arn:${AWS::Partition}:iam::${AWS::AccountId}:role/${ProjectName}-cf-deployer
##########
# Lambda #
##########
- Sid: Lambda
Effect: Allow
Action: lambda:*
Resource:
- !Sub arn:${AWS::Partition}:lambda:${AWS::Region}:${AWS::AccountId}:function:${ProjectName}-*
- !Sub arn:${AWS::Partition}:lambda:${AWS::Region}:${AWS::AccountId}:event-source-mapping:*
- Sid: LambdaESM
Effect: Allow
Action: lambda:*EventSourceMapping*
Resource: "*"
#######
# IAM #
#######
# IAM keeps explicit actions: iam:* on a role ARN could still allow
# dangerous operations like CreateServiceLinkedRole or
# PutRolePermissionsBoundary that go beyond simple CRUD.
- Sid: IamRoles
Effect: Allow
Action:
- iam:CreateRole
- iam:GetRole
- iam:UpdateRole
- iam:DeleteRole
- iam:PassRole
- iam:TagRole
- iam:UntagRole
- iam:ListRoleTags
- iam:PutRolePolicy
- iam:GetRolePolicy
- iam:DeleteRolePolicy
- iam:AttachRolePolicy
- iam:DetachRolePolicy
- iam:ListRolePolicies
- iam:ListAttachedRolePolicies
Resource:
- !Sub arn:${AWS::Partition}:iam::${AWS::AccountId}:role/${ProjectName}-*
################
# CloudWatch Logs
################
- Sid: LogGroups
Effect: Allow
Action: logs:*
Resource:
- !Sub arn:${AWS::Partition}:logs:${AWS::Region}:${AWS::AccountId}:log-group:/aws/lambda/${ProjectName}-*
- !Sub arn:${AWS::Partition}:logs:${AWS::Region}:${AWS::AccountId}:log-group:/aws/appsync/apis/*
- Sid: DescribeLogGroups
Effect: Allow
Action: logs:DescribeLogGroups
Resource: "*"
######
# S3 #
######
- Sid: S3WebsiteBucket
Effect: Allow
Action: s3:*
Resource:
- !Sub arn:${AWS::Partition}:s3:::${ProjectName}-${AWS::AccountId}-${AWS::Region}-website
##############
# CloudFront #
##############
- Sid: CloudFront
Effect: Allow
Action: cloudfront:*
Resource:
- !Sub arn:${AWS::Partition}:cloudfront::${AWS::AccountId}:distribution/*
- !Sub arn:${AWS::Partition}:cloudfront::${AWS::AccountId}:origin-access-control/*
- !Sub arn:${AWS::Partition}:cloudfront::${AWS::AccountId}:response-headers-policy/*
############
# DynamoDB #
############
- Sid: DynamoDB
Effect: Allow
Action: dynamodb:*
Resource:
- !Sub arn:${AWS::Partition}:dynamodb:${AWS::Region}:${AWS::AccountId}:table/${ProjectName}-*
###########
# AppSync #
###########
- Sid: AppSync
Effect: Allow
Action: appsync:*
Resource:
- !Sub arn:${AWS::Partition}:appsync:${AWS::Region}:${AWS::AccountId}:*
###########
# Cognito #
###########
- Sid: Cognito
Effect: Allow
Action: cognito-idp:*
Resource:
- !Sub arn:${AWS::Partition}:cognito-idp:${AWS::Region}:${AWS::AccountId}:userpool/*
Path: /
Outputs:
CustomResourceBucketEmptier:
Description: Arn of the Lambda used as a CFN Custom Resource to empty buckets
Value: !GetAtt BucketEmptierLambda.Arn
# Export makes this output available to OTHER stacks via Fn::ImportValue (cross-stack reference).
# The static-website stack imports this to reuse the bucket emptier Lambda.
Export:
Name: !Sub CustomResource:${ProjectName}:S3BucketEmptier