Skip to content

Commit 0a9bfc6

Browse files
committed
update cfn
1 parent 0c7e9aa commit 0a9bfc6

File tree

2 files changed

+57
-6
lines changed

2 files changed

+57
-6
lines changed

Makefile

Lines changed: 8 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -4,8 +4,10 @@ set_application_name = ParameterKey=ApplicationFriendlyName,ParameterValue
44

55
prod_aws_account = 298118738376
66
dev_aws_account = 427040638965
7+
current_aws_account = $$(aws sts get-caller-identity --query Account --output text)
78

89
src_directory_root = src/
10+
dist_ui_directory_root = dist_ui/
911
integration_test_directory_root = tests/live_integration/
1012

1113
# CHANGE ME (as needed)
@@ -24,19 +26,19 @@ common_params = --no-confirm-changeset \
2426
--s3-prefix $(application_key) \
2527
--resolve-s3
2628

29+
ui_s3_bucket = "$(current_aws_account)-$(region)-$(application_key)-ui"
30+
2731
GIT_HASH := $(shell git rev-parse --short HEAD)
2832

2933
.PHONY: build clean
3034

3135
check_account_prod:
32-
@aws_account_id=$$(aws sts get-caller-identity --query Account --output text); \
33-
if [ "$$aws_account_id" != "$(prod_aws_account)" ]; then \
36+
if [ "$(current_aws_account)" != "$(prod_aws_account)" ]; then \
3437
echo "Error: running in incorrect account $$aws_account_id, expected account ID $(prod_aws_account)"; \
3538
exit 1; \
3639
fi
3740
check_account_dev:
38-
@aws_account_id=$$(aws sts get-caller-identity --query Account --output text); \
39-
if [ "$$aws_account_id" != "$(dev_aws_account)" ]; then \
41+
if [ "$(current_aws_account)" != "$(dev_aws_account)" ]; then \
4042
echo "Error: running in incorrect account $$aws_account_id, expected account ID $(dev_aws_account)"; \
4143
exit 1; \
4244
fi
@@ -61,11 +63,12 @@ local:
6163
VITE_BUILD_HASH=$(GIT_HASH) yarn run dev
6264

6365
deploy_prod: check_account_prod build
64-
aws sts get-caller-identity --query Account --output text
6566
sam deploy $(common_params) --parameter-overrides $(run_env)=prod $(set_application_prefix)=$(application_key) $(set_application_name)="$(application_name)"
67+
aws s3 sync $(dist_ui_directory_root) s3://$(ui_s3_bucket)/ --delete
6668

6769
deploy_dev: check_account_dev build
6870
sam deploy $(common_params) --parameter-overrides $(run_env)=dev $(set_application_prefix)=$(application_key) $(set_application_name)="$(application_name)"
71+
aws s3 sync $(dist_ui_directory_root) s3://$(ui_s3_bucket)/ --delete
6972

7073
install:
7174
yarn -D

cloudformation/main.yml

Lines changed: 49 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
AWSTemplateFormatVersion: 2010-09-09
2-
Description: Events API v2
2+
Description: ACM Core Management Platform
33
Transform: AWS::Serverless-2016-10-31
44

55
Parameters:
@@ -518,3 +518,51 @@ Resources:
518518
Type: AWS::S3::Bucket
519519
Properties:
520520
BucketName: !Sub ${AWS::AccountId}-${AWS::Region}-${ApplicationPrefix}-ui
521+
522+
CloudFrontOriginAccessIdentity:
523+
Type: AWS::CloudFront::CloudFrontOriginAccessIdentity
524+
Properties:
525+
CloudFrontOriginAccessIdentityConfig:
526+
Comment: !Sub "Access identity for ${AppFrontendS3Bucket}"
527+
528+
AppFrontendCloudfrontDistribution:
529+
Type: AWS::CloudFront::Distribution
530+
Properties:
531+
DistributionConfig:
532+
Origins:
533+
- Id: S3WebsiteOrigin
534+
DomainName: !GetAtt AppFrontendS3Bucket.RegionalDomainName
535+
S3OriginConfig:
536+
OriginAccessIdentity: !Sub "origin-access-identity/cloudfront/${CloudFrontOriginAccessIdentity}"
537+
Enabled: true
538+
DefaultRootObject: index.html
539+
DefaultCacheBehavior:
540+
TargetOriginId: S3WebsiteOrigin
541+
ViewerProtocolPolicy: redirect-to-https
542+
AllowedMethods:
543+
- GET
544+
- HEAD
545+
CachedMethods:
546+
- GET
547+
- HEAD
548+
ForwardedValues:
549+
QueryString: false
550+
Cookies:
551+
Forward: none
552+
ViewerCertificate:
553+
CloudFrontDefaultCertificate: true
554+
HttpVersion: http2
555+
PriceClass: PriceClass_100
556+
557+
AppFrontendS3BucketPolicy:
558+
Type: AWS::S3::BucketPolicy
559+
Properties:
560+
Bucket: !Ref AppFrontendS3Bucket
561+
PolicyDocument:
562+
Version: "2012-10-17"
563+
Statement:
564+
- Effect: Allow
565+
Principal:
566+
CanonicalUser: !GetAtt CloudFrontOriginAccessIdentity.S3CanonicalUserId
567+
Action: s3:GetObject
568+
Resource: !Sub "${AppFrontendS3Bucket.Arn}/*"

0 commit comments

Comments
 (0)