-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathroot-template.yml
More file actions
76 lines (73 loc) · 3.04 KB
/
root-template.yml
File metadata and controls
76 lines (73 loc) · 3.04 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
AWSTemplateFormatVersion: 2010-09-09
Description: Main project stack deployed by the CICD and containing specific nested stacks
# Parameters are user-provided inputs injected when the stack is deployed.
# Here, ProjectName is passed through to every nested stack to namespace all resources.
Parameters:
ProjectName:
Type: String
Resources:
# Each nested stack (AWS::CloudFormation::Stack) deploys a separate template as a child stack.
# This keeps the infrastructure modular: website, auth, and API are independent units.
StaticWebsiteStack:
Type: AWS::CloudFormation::Stack
Properties:
Parameters:
ProjectName: !Ref ProjectName
# Relative path to the nested template file.
# `aws cloudformation package` (run during the CI build) uploads it to S3 and rewrites this to an S3 URL.
TemplateURL: ./templates/static-website.yml
TimeoutInMinutes: 15
Tags:
- Key: Project
Value: !Ref ProjectName
CognitoStack:
Type: AWS::CloudFormation::Stack
Properties:
Parameters:
ProjectName: !Ref ProjectName
# !GetAtt retrieves an output from an already-deployed nested stack.
# This also creates an implicit dependency: CognitoStack waits for StaticWebsiteStack to finish.
WebsiteDomainName: !GetAtt StaticWebsiteStack.Outputs.WebsiteDomainName
TemplateURL: ./templates/cognito.yml
TimeoutInMinutes: 10
Tags:
- Key: Project
Value: !Ref ProjectName
GraphQLApiStack:
Type: AWS::CloudFormation::Stack
Properties:
Parameters:
ProjectName: !Ref ProjectName
# Pass Cognito outputs as inputs to the GraphQL API stack.
# This wires the authentication layer to the API.
CognitoUserPoolId: !GetAtt CognitoStack.Outputs.CognitoUserPoolId
CognitoUserPoolClientId: !GetAtt CognitoStack.Outputs.CognitoUserPoolClientId
TemplateURL: ./templates/graphqlapi.yml
TimeoutInMinutes: 10
Tags:
- Key: Project
Value: !Ref ProjectName
# Outputs expose values from nested stacks so the CI/CD pipeline and website build can consume them.
Outputs:
StaticWebBucket:
Description: Name of the web bucket containing the website
Value: !GetAtt StaticWebsiteStack.Outputs.StaticWebBucket
WebsiteUrl:
Description: URL of the website
# !Sub performs string interpolation, embedding the CloudFront domain name into a full URL
Value: !Sub https://${StaticWebsiteStack.Outputs.WebsiteDomainName}/
CognitoUserPoolId:
Description: The Cognito UserPool ID
Value: !GetAtt CognitoStack.Outputs.CognitoUserPoolId
CognitoUserPoolClientId:
Description: The Cognito UserPool client ID
Value: !GetAtt CognitoStack.Outputs.CognitoUserPoolClientId
CognitoDomainName:
Description: Domain of Cognito
Value: !GetAtt CognitoStack.Outputs.CognitoDomainName
GraphQLApiUrl:
Description: GraphQL API URL
Value: !GetAtt GraphQLApiStack.Outputs.ApiUrl
GraphQLApiKey:
Description: The Public API key of the API
Value: !GetAtt GraphQLApiStack.Outputs.ApiKey