Skip to content

Commit a79fb72

Browse files
authored
Merge pull request #68 from tyrauber/feature/acm_certificate_arn
Adds ACM_CERTIFICATE_ARN configuration variable
2 parents 98a0124 + cfa7ae2 commit a79fb72

File tree

3 files changed

+24
-7
lines changed

3 files changed

+24
-7
lines changed

docs/configuration.md

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -35,12 +35,14 @@ stages:
3535
<<: *defaults.environment
3636
SECURITY_KEY: ''
3737
CUSTOM_DOMAIN: ''
38+
ACM_CERTIFICATE_ARN: ''
3839
prod:
3940
<<: *defaults
4041
environment:
4142
<<: *defaults.environment
4243
SECURITY_KEY: 'random-string-here'
4344
CUSTOM_DOMAIN: 'img.mydomain.com'
45+
ACM_CERTIFICATE_ARN: ''
4446
```
4547
4648
## Environment Settings
@@ -50,6 +52,7 @@ The majority of the application and environment specific settings are configured
5052
|Setting|Default|
5153
|-|-|
5254
|[CUSTOM_DOMAIN](#custom_domain)|*empty*|
55+
|[ACM_CERTIFICATE_ARN])(#acm_certificate_arn)|*empty*]
5356
|[DEFAULT_CACHE_CONTROL](#default_cache_control)|*empty*|
5457
|[DEFAULT_COMPRESS_QUALITY](#default_compress_quality)|75|
5558
|[DEFAULT_QUALITY](#default_quality)|75|
@@ -82,6 +85,12 @@ During deployment, you'll need to go into your Amazon ACM console and verify the
8285

8386
</Note>
8487

88+
### `ACM_CERTIFICATE_ARN`
89+
- type: `string`
90+
- DEFAULT: *empty*
91+
92+
Use an existing ACM Certificate, by supplying the ACM Certificate Arn.
93+
8594
### `DEFAULT_CACHE_CONTROL`
8695

8796
- Type: `string`

serverless.yml

Lines changed: 13 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -32,7 +32,11 @@ layers:
3232

3333
resources:
3434
Conditions:
35-
CreateCertificate: !Not [ !Equals [ "${self:custom.settings.environment.CUSTOM_DOMAIN, ''}", "" ] ]
35+
CustomDomain: !Not [!Equals ["${self:custom.settings.environment.CUSTOM_DOMAIN, ''}", ""]]
36+
ArnCertificate: !Not [!Equals ["${self:custom.settings.environment.ACM_CERTIFICATE_ARN, ''}", ""]]
37+
CreateCertificate: !And
38+
- !Not [!Equals ["${self:custom.settings.environment.CUSTOM_DOMAIN, ''}", ""]]
39+
- !Equals ["${self:custom.settings.environment.ACM_CERTIFICATE_ARN, ''}", ""]
3640
Resources:
3741
CloudFrontDistribution:
3842
Type: AWS::CloudFront::Distribution
@@ -62,23 +66,25 @@ resources:
6266
OriginProtocolPolicy: https-only
6367
Aliases:
6468
Fn::If:
65-
- CreateCertificate
66-
- - '${self:custom.settings.environment.CUSTOM_DOMAIN, self:custom.empty}'
67-
- Ref: AWS::NoValue
69+
- CustomDomain
70+
- - '${self:custom.settings.environment.CUSTOM_DOMAIN, self:custom.empty}'
71+
- Ref: AWS::NoValue
6872
ViewerCertificate:
6973
Fn::If:
7074
- CreateCertificate
71-
- AcmCertificateArn:
72-
Ref: Certificate
75+
- AcmCertificateArn: !If
76+
- ArnCertificate
77+
- self:custom.settings.environment.ACM_CERTIFICATE_ARN
78+
- Ref: Certificate
7379
SslSupportMethod: 'sni-only'
7480
MinimumProtocolVersion: 'TLSv1'
7581
- Ref: AWS::NoValue
7682
Certificate:
7783
Type: AWS::CertificateManager::Certificate
7884
Condition: CreateCertificate
7985
Properties:
80-
DomainName: '${self:custom.settings.environment.CUSTOM_DOMAIN}'
8186
ValidationMethod: DNS
87+
DomainName: '${self:custom.settings.environment.CUSTOM_DOMAIN}'
8288
Outputs:
8389
CloudFrontDistributionOutput:
8490
Value:

settings.example.yml

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -20,10 +20,12 @@ stages:
2020
SOURCE_BUCKET: 'my-bucket/prefix/path'
2121
SECURITY_KEY: ''
2222
CUSTOM_DOMAIN: ''
23+
ACM_CERTIFICATE_ARN: ''
2324
prod:
2425
<<: *defaults
2526
environment:
2627
<<: *defaults.environment
2728
SOURCE_BUCKET: 'random-string-here'
2829
SECURITY_KEY: ''
2930
CUSTOM_DOMAIN: 'my.domain.com'
31+
ACM_CERTIFICATE_ARN: ''

0 commit comments

Comments
 (0)