Skip to content
Permalink
Branch: master
Find file Copy path
Find file Copy path
1 contributor

Users who have contributed to this file

149 lines (136 sloc) 4.62 KB
AWSTemplateFormatVersion: 2010-09-09
Description: >
Creates the AWS infrastructure for running an Angular app in AWS using S3, CloudFront & Route53
Parameters:
BaseUrl:
Type: String
Default: bliskavka.com
Description : The DNS name of an existing Amazon Route 53 hosted zone,
AllowedPattern : (?!-)[a-zA-Z0-9-.]{1,63}(?<!-)[^\\.]$
ConstraintDescription : Must be a valid DNS zone name WITHOUT trailing period.
AppUrl:
Type: String
Default: example.bliskavka.com
Description: The subdomain you want to use for your app. Use www for your main domain.
AcmCertArn:
Type: String
Description: ARN of the Amazon Certificate Manager cert to use for SSL
Resources:
# https://docs.aws.amazon.com/AWSCloudFormation/latest/UserGuide/aws-properties-s3-bucket.html
AppBucket:
Type: AWS::S3::Bucket
Properties:
AccessControl: PublicRead
WebsiteConfiguration:
IndexDocument: index.html
# https://docs.aws.amazon.com/AWSCloudFormation/latest/UserGuide/aws-properties-s3-policy.html
AppBucketPolicy:
Type: AWS::S3::BucketPolicy
Properties:
PolicyDocument:
Id: WebAppBucketPolicy
Version: 2012-10-17
Statement:
- Sid: PublicReadForGetBucketObjects
Effect: Allow
Principal: '*'
Action: 's3:GetObject'
Resource: !Join
- ''
- - 'arn:aws:s3:::'
- !Ref AppBucket
- /*
Bucket: !Ref AppBucket
# https://docs.aws.amazon.com/AWSCloudFormation/latest/UserGuide/aws-resource-cloudfront-cloudfrontoriginaccessidentity.html
OriginAccessIdentity:
Type: AWS::CloudFront::CloudFrontOriginAccessIdentity
Properties:
CloudFrontOriginAccessIdentityConfig:
Comment: Access identity between CloudFront and S3 bucket
# https://docs.aws.amazon.com/AWSCloudFormation/latest/UserGuide/aws-resource-cloudfront-distribution.html
AppDistribution:
Type: AWS::CloudFront::Distribution
Properties:
DistributionConfig:
Origins:
- DomainName: !Sub ${AppBucket}.s3.amazonaws.com
Id: myS3Origin
S3OriginConfig:
OriginAccessIdentity: !Sub origin-access-identity/cloudfront/${OriginAccessIdentity}
Enabled: 'true'
Comment: CloudFront distribution for Angular App
CustomErrorResponses:
- ErrorCachingMinTTL: 5
ErrorCode: 404
ResponseCode: 200
ResponsePagePath: /index.html
DefaultRootObject: index.html
Aliases:
- !Ref AppUrl
#- !Ref BaseUrl # Uncomment this if you want to map your domain root
DefaultCacheBehavior:
AllowedMethods:
- GET
- HEAD
- OPTIONS
Compress: 'true'
TargetOriginId: myS3Origin
ForwardedValues:
QueryString: 'false'
Cookies:
Forward: none
ViewerProtocolPolicy: redirect-to-https
PriceClass: PriceClass_100
ViewerCertificate:
AcmCertificateArn: !Ref AcmCertArn
SslSupportMethod: sni-only
# https://docs.aws.amazon.com/AWSCloudFormation/latest/UserGuide/aws-properties-route53-recordsetgroup.html
WebAppDns:
Type: AWS::Route53::RecordSetGroup
Properties:
HostedZoneName: !Sub ${BaseUrl}.
Comment: IP4 & IP6 alias targeted to CloudFront Distribution.
RecordSets:
- Name: !Ref AppUrl
Type: A
AliasTarget:
HostedZoneId: Z2FDTNDATAQYW2
DNSName: !GetAtt
- AppDistribution
- DomainName
- Name: !Ref AppUrl
Type: AAAA
AliasTarget:
HostedZoneId: Z2FDTNDATAQYW2
DNSName: !GetAtt
- AppDistribution
- DomainName
# - Name: !Ref BaseUrl # Uncomment this area if you want to map your domain root
# Type: A
# AliasTarget:
# HostedZoneId: Z2FDTNDATAQYW2
# DNSName: !GetAtt
# - AppDistribution
# - DomainName
# - Name: !Ref BaseUrl
# Type: AAAA
# AliasTarget:
# HostedZoneId: Z2FDTNDATAQYW2
# DNSName: !GetAtt
# - AppDistribution
# - DomainName
Outputs:
AppBucket:
Description: S3 Bucket hosting our demo-app
Value: !Ref AppBucket
DistributionId:
Value: !Ref AppDistribution
Description: CloudFront DistributionId
CloudFrontURL:
Value: !Join
- ''
- - 'https://'
- !GetAtt
- AppDistribution
- DomainName
Description: URL for website CDN
You can’t perform that action at this time.