-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathcodestar-template.yml
651 lines (651 loc) · 17.9 KB
/
codestar-template.yml
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
AWSTemplateFormatVersion: 2010-09-09
Conditions:
CreateCodeBuildResources: !Equals
- true
- true
CreateWebSiteS3Bucket: !Equals
- false
- true
Description: A Node.js web service deployed to AWS Lambda.
Metadata:
AWS::CloudFormation::Interface:
ParameterGroups:
- Label:
default: Application
Parameters:
- ProjectId
CodeBuildImage: aws/codebuild/eb-nodejs-6.10.0-amazonlinux-64:4.0.0
CodeBuildImageOverride: aws/codebuild/eb-nodejs-6.10.0-amazonlinux-64:4.0.0
IsWebsite: false
ProjectTemplateId: webservice-nodeexpress-lambda
WebsiteS3Bucket: !Ref 'WebsiteS3Bucket'
Outputs:
LambdaTrustRole:
Description: AWS CodeStar role for AWS Lambda used for passRole to Lambda functions.
Export:
Name: !Join
- '-'
- - !Ref 'ProjectId'
- !Ref 'AWS::Region'
- LambdaTrustRole
Value: !GetAtt 'LambdaTrustRole.Arn'
Parameters:
AppName:
Description: Name of the application.
MaxLength: 100
MinLength: 1
Type: String
ProjectId:
AllowedPattern: ^[a-z]([a-z0-9-])+$
ConstraintDescription: Project IDs must be between 2 and 15 characters, begin with a letter, and only contain lowercase letters, numbers, and hyphens (-).
Description: Project ID.
MaxLength: 15
MinLength: 2
Type: String
RepositoryBranch:
Default: master
Description: GitHub branch name.
Type: String
RepositoryEnableIssues:
AllowedValues:
- true
- false
Default: false
Description: Whether the GitHub issues tile is enabled.
Type: String
RepositoryName:
Description: GitHub repository name.
MaxLength: 100
MinLength: 1
Type: String
RepositoryProvider:
Default: GitHub
Description: Repository provider.
Type: String
RepositoryProviderUserId:
Description: GitHub user ID.
Type: String
RepositoryProviderUsername:
Description: GitHub user name.
Type: String
RepositoryToken:
Description: GitHub access token.
NoEcho: true
Type: String
RepositoryURL:
Description: GitHub repository URL.
Type: String
Resources:
CloudFormationTrustRole:
Description: Creating service role in IAM for AWS CloudFormation
Properties:
AssumeRolePolicyDocument:
Statement:
- Action: sts:AssumeRole
Effect: Allow
Principal:
Service:
- cloudformation.amazonaws.com
Path: /
Policies:
- PolicyDocument:
Statement:
- Action:
- s3:PutObject
- s3:GetObject
- s3:GetObjectVersion
Effect: Allow
Resource:
- !Join
- ''
- - 'arn:aws:s3:::'
- !Ref 'S3Bucket'
- !Join
- ''
- - 'arn:aws:s3:::'
- !Ref 'S3Bucket'
- /*
- Action:
- codestar:SyncResources
- lambda:CreateFunction
- lambda:DeleteFunction
- lambda:AddPermission
- lambda:UpdateFunction
- lambda:UpdateFunctionCode
- lambda:GetFunction
- lambda:GetFunctionConfiguration
- lambda:UpdateFunctionConfiguration
- lambda:RemovePermission
- lambda:listTags
- lambda:TagResource
- lambda:UntagResource
- apigateway:*
- dynamodb:CreateTable
- dynamodb:DeleteTable
- dynamodb:DescribeTable
- kinesis:CreateStream
- kinesis:DeleteStream
- kinesis:DescribeStream
- sns:CreateTopic
- sns:DeleteTopic
- sns:ListTopics
- sns:GetTopicAttributes
- sns:SetTopicAttributes
- s3:CreateBucket
- s3:DeleteBucket
- config:DescribeConfigRules
- config:PutConfigRule
- config:DeleteConfigRule
Effect: Allow
Resource: '*'
- Action:
- iam:PassRole
Effect: Allow
Resource:
- !GetAtt
- LambdaTrustRole
- Arn
- Action:
- cloudformation:CreateChangeSet
Effect: Allow
Resource:
- arn:aws:cloudformation:us-east-1:aws:transform/Serverless-2016-10-31
- arn:aws:cloudformation:us-east-1:aws:transform/CodeStar
PolicyName: CodeStarWorkerCloudFormationRolePolicy
RoleName: !Join
- '-'
- - CodeStarWorker
- !Ref 'ProjectId'
- CloudFormation
Type: AWS::IAM::Role
CodeBuildPolicy:
Condition: CreateCodeBuildResources
Description: Setting IAM policy for service role for Amazon EC2 instances
Properties:
PolicyDocument:
Statement:
- Action:
- logs:CreateLogGroup
- logs:CreateLogStream
- logs:PutLogEvents
Effect: Allow
Resource: '*'
- Action:
- s3:PutObject
- s3:GetObject
- s3:GetObjectVersion
Effect: Allow
Resource:
- !Join
- ''
- - 'arn:aws:s3:::'
- !Ref 'S3Bucket'
- !Join
- ''
- - 'arn:aws:s3:::'
- !Ref 'S3Bucket'
- /*
- !If
- CreateWebSiteS3Bucket
- Action:
- s3:PutObject*
- s3:GetObject
- s3:GetObjectVersion
Effect: Allow
Resource:
- !Join
- ''
- - 'arn:aws:s3:::'
- !Ref 'WebsiteS3Bucket'
- !Join
- ''
- - 'arn:aws:s3:::'
- !Ref 'WebsiteS3Bucket'
- /*
- !Ref 'AWS::NoValue'
- Action:
- kms:GenerateDataKey*
- kms:Encrypt
- kms:Decrypt
Effect: Allow
Resource:
- !Join
- ':'
- - arn:aws:kms
- !Ref 'AWS::Region'
- !Ref 'AWS::AccountId'
- !Join
- /
- - alias
- aws/s3
PolicyName: CodeStarWorkerCodeBuildPolicy
Roles:
- !Ref 'CodeBuildRole'
Type: AWS::IAM::Policy
CodeBuildProject:
Condition: CreateCodeBuildResources
DependsOn:
- CodeBuildPolicy
Properties:
Artifacts:
Packaging: zip
Type: codepipeline
Description: !Join
- ''
- - 'AWS CodeStar created CodeBuild Project for '
- !Ref 'AppName'
Environment:
ComputeType: small
EnvironmentVariables:
- Name: S3_BUCKET
Value: !Ref 'S3Bucket'
- Name: WEBSITE_S3_PREFIX
Value: !If
- CreateWebSiteS3Bucket
- !Join
- ''
- - https://s3.amazonaws.com/
- !Ref 'WebsiteS3Bucket'
- NoVal
- Name: WEBSITE_S3_BUCKET
Value: !If
- CreateWebSiteS3Bucket
- !Ref 'WebsiteS3Bucket'
- NoVal
Image: aws/codebuild/eb-nodejs-6.10.0-amazonlinux-64:4.0.0
Type: container
Name: !Ref 'ProjectId'
ServiceRole: !Ref 'CodeBuildRole'
Source:
Type: codepipeline
Type: AWS::CodeBuild::Project
CodeBuildRole:
Condition: CreateCodeBuildResources
Description: Creating service role in IAM for Amazon EC2 instances
Properties:
AssumeRolePolicyDocument:
Statement:
- Action: sts:AssumeRole
Effect: Allow
Principal:
Service: codebuild.amazonaws.com
Path: /
RoleName: !Join
- '-'
- - CodeStarWorker
- !Ref 'ProjectId'
- CodeBuild
Type: AWS::IAM::Role
CodePipelineTrustRole:
Description: Creating service role in IAM for AWS CodePipeline
Properties:
AssumeRolePolicyDocument:
Statement:
- Action: sts:AssumeRole
Effect: Allow
Principal:
Service:
- codepipeline.amazonaws.com
Sid: 1
Path: /
Policies:
- PolicyDocument:
Statement:
- Action:
- s3:GetObject
- s3:GetObjectVersion
- s3:GetBucketVersioning
- s3:PutObject
Effect: Allow
Resource:
- !Join
- ''
- - 'arn:aws:s3:::'
- !Ref 'S3Bucket'
- !Join
- ''
- - 'arn:aws:s3:::'
- !Ref 'S3Bucket'
- /*
- Action:
- codebuild:StartBuild
- codebuild:BatchGetBuilds
- codebuild:StopBuild
Effect: Allow
Resource:
- !GetAtt 'CodeBuildProject.Arn'
- Action:
- cloudformation:DescribeStacks
- cloudformation:DescribeChangeSet
- cloudformation:CreateChangeSet
- cloudformation:DeleteChangeSet
- cloudformation:ExecuteChangeSet
Effect: Allow
Resource:
- !Join
- ':'
- - arn
- aws
- cloudformation
- !Ref 'AWS::Region'
- !Ref 'AWS::AccountId'
- !Join
- /
- - stack
- !Join
- '-'
- - awscodestar
- !Ref 'ProjectId'
- lambda
- '*'
- Action:
- iam:PassRole
Effect: Allow
Resource:
- !GetAtt
- CloudFormationTrustRole
- Arn
PolicyName: CodeStarWorkerCodePipelineRolePolicy
RoleName: !Join
- '-'
- - CodeStarWorker
- !Ref 'ProjectId'
- CodePipeline
Type: AWS::IAM::Role
CodeStarProject:
Description: Starting project creation
Properties:
ProjectDescription: AWS CodeStar created project
ProjectId: !Ref 'ProjectId'
ProjectName: !Ref 'AppName'
ProjectTemplateId: arn:aws:codestar:us-east-1::project-template/github/webservice-nodeexpress-lambda
StackId: !Ref 'AWS::StackId'
Type: AWS::CodeStar::Project
Version: 1.0
LambdaTrustRole:
Description: Creating service role in IAM for AWS Lambda
Properties:
AssumeRolePolicyDocument:
Statement:
- Action: sts:AssumeRole
Effect: Allow
Principal:
Service:
- lambda.amazonaws.com
ManagedPolicyArns:
- arn:aws:iam::aws:policy/service-role/AWSLambdaBasicExecutionRole
- arn:aws:iam::aws:policy/service-role/AWSConfigRulesExecutionRole
Path: /
Policies:
- PolicyDocument:
Statement:
- Action:
- logs:CreateLogGroup
- logs:CreateLogStream
- logs:PutLogEvents
Effect: Allow
Resource: '*'
Version: 2012-10-17
PolicyName: CodeStarLambdaWorkerPolicy
RoleName: !Join
- '-'
- - CodeStarWorker
- !Ref 'ProjectId'
- Lambda
Type: AWS::IAM::Role
ProjectPipeline:
DependsOn:
- SeedRepo
- LambdaTrustRole
- CodePipelineTrustRole
- S3Bucket
- CodeBuildProject
- CloudFormationTrustRole
Description: Creating a deployment pipeline for your project in AWS CodePipeline
Properties:
ArtifactStore:
Location: !Ref 'S3Bucket'
Type: S3
Name: !Join
- '-'
- - !Ref 'ProjectId'
- Pipeline
RoleArn: !GetAtt
- CodePipelineTrustRole
- Arn
Stages:
- Actions:
- ActionTypeId:
Category: Source
Owner: ThirdParty
Provider: GitHub
Version: 1
Configuration:
Branch: !Ref 'RepositoryBranch'
OAuthToken: !Ref 'RepositoryToken'
Owner: !Ref 'RepositoryProviderUsername'
Repo: !Ref 'RepositoryName'
InputArtifacts: [
]
Name: ApplicationSource
OutputArtifacts:
- Name: !Join
- '-'
- - !Ref 'ProjectId'
- SourceArtifact
RunOrder: 1
Name: Source
- Actions:
- ActionTypeId:
Category: Build
Owner: AWS
Provider: CodeBuild
Version: 1
Configuration:
ProjectName: !Ref 'ProjectId'
InputArtifacts:
- Name: !Join
- '-'
- - !Ref 'ProjectId'
- SourceArtifact
Name: PackageExport
OutputArtifacts:
- Name: !Join
- '-'
- - !Ref 'ProjectId'
- BuildArtifact
RunOrder: 1
Name: Build
- Actions:
- ActionTypeId:
Category: Deploy
Owner: AWS
Provider: CloudFormation
Version: 1
Configuration:
ActionMode: CHANGE_SET_REPLACE
Capabilities: CAPABILITY_IAM
ChangeSetName: pipeline-changeset
ParameterOverrides: !Join
- ''
- - '{"ProjectId":"'
- !Ref 'ProjectId'
- '"}'
RoleArn: !GetAtt
- CloudFormationTrustRole
- Arn
StackName: !Join
- '-'
- - awscodestar
- !Ref 'ProjectId'
- lambda
TemplatePath: !Join
- ''
- - !Ref 'ProjectId'
- -BuildArtifact
- ::template-export.yml
InputArtifacts:
- Name: !Join
- '-'
- - !Ref 'ProjectId'
- BuildArtifact
Name: GenerateChangeSet
OutputArtifacts: [
]
RunOrder: 1
- ActionTypeId:
Category: Deploy
Owner: AWS
Provider: CloudFormation
Version: 1
Configuration:
ActionMode: CHANGE_SET_EXECUTE
ChangeSetName: pipeline-changeset
StackName: !Join
- '-'
- - awscodestar
- !Ref 'ProjectId'
- lambda
InputArtifacts: [
]
Name: ExecuteChangeSet
OutputArtifacts: [
]
RunOrder: 2
Name: Deploy
Type: AWS::CodePipeline::Pipeline
S3ArtifactBucketPolicy:
Description: Setting Amazon S3 bucket policy for AWS CodePipeline access
Properties:
Bucket: !Ref 'S3Bucket'
PolicyDocument:
Id: SSEAndSSLPolicy
Statement:
- Action:
- s3:GetObject
- s3:GetObjectVersion
- s3:GetBucketVersioning
Condition:
Bool:
aws:SecureTransport: false
Effect: Allow
Principal:
AWS:
- !GetAtt
- CodePipelineTrustRole
- Arn
- !GetAtt
- CodeBuildRole
- Arn
- !GetAtt
- CloudFormationTrustRole
- Arn
Resource:
- !Join
- ''
- - 'arn:aws:s3:::'
- !Ref 'S3Bucket'
- !Join
- ''
- - 'arn:aws:s3:::'
- !Ref 'S3Bucket'
- /*
Sid: WhitelistedGet
- Action:
- s3:PutObject
Effect: Allow
Principal:
AWS:
- !GetAtt
- CodePipelineTrustRole
- Arn
- !GetAtt
- CodeBuildRole
- Arn
Resource:
- !Join
- ''
- - 'arn:aws:s3:::'
- !Ref 'S3Bucket'
- !Join
- ''
- - 'arn:aws:s3:::'
- !Ref 'S3Bucket'
- /*
Sid: WhitelistedPut
Version: 2012-10-17
Type: AWS::S3::BucketPolicy
S3Bucket:
DeletionPolicy: Retain
Description: Creating Amazon S3 bucket for AWS CodePipeline artifacts
Properties:
BucketName: !Join
- '-'
- - aws
- codestar
- !Ref 'AWS::Region'
- !Ref 'AWS::AccountId'
- !Ref 'ProjectId'
- pipe
Tags:
- Key: Name
Value: !Join
- '-'
- - !Ref 'ProjectId'
- S3Bucket
VersioningConfiguration:
Status: Enabled
Type: AWS::S3::Bucket
SeedRepo:
DeletionPolicy: Retain
Description: Adding application source code to the GitHub repository for the project.
Properties:
DefaultBranchName: !Ref 'RepositoryBranch'
ProjectId: !Ref 'ProjectId'
ProjectTemplateId: arn:aws:codestar:us-east-1::project-template/github/webservice-nodeexpress-lambda
RepositoryProvider: !Ref 'RepositoryProvider'
RepositoryProviderUsername: !Ref 'RepositoryProviderUsername'
RepositoryToken: !Ref 'RepositoryToken'
RepositoryURL: !Ref 'RepositoryURL'
Type: AWS::CodeStar::SeedRepository
SyncInitialResources:
DependsOn:
- SeedRepo
Description: Getting GitHub issues tile settings for your AWS CodeStar project.
Properties:
ProjectId: !Ref 'ProjectId'
Type: AWS::CodeStar::SyncResources
Version: 1.0
SyncResources:
DependsOn:
- SeedRepo
- CodeBuildProject
- ProjectPipeline
- SyncInitialResources
Description: Adding all created resources to your AWS CodeStar project
Properties:
ProjectId: !Ref 'ProjectId'
Type: AWS::CodeStar::SyncResources
Version: 1.0
WebsiteS3Bucket:
Condition: CreateWebSiteS3Bucket
DeletionPolicy: Retain
Description: Creating Amazon S3 bucket for Website static artifacts
Properties:
BucketName: !Join
- '-'
- - aws
- codestar
- !Ref 'AWS::Region'
- !Ref 'AWS::AccountId'
- !Ref 'ProjectId'
- app
Tags:
- Key: Name
Value: !Join
- '-'
- - !Ref 'ProjectId'
- WebsiteS3Bucket
VersioningConfiguration:
Status: Enabled
Type: AWS::S3::Bucket