Skip to content

Commit 8d861ea

Browse files
author
amazon-meaisiah
committed
Add a variable so people can reset the edge lambda
This could be necessary in the future, so I want to lay the groundwork now. Also, it's a potentially common need in development.
1 parent 12c388e commit 8d861ea

File tree

6 files changed

+28
-2
lines changed

6 files changed

+28
-2
lines changed

BUILDING.md

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -146,6 +146,16 @@ AWS SAM CLI profile option: optional specific profile from your AWS credential f
146146

147147
Set this to `true` if you want to enable development mode. It's `false` by default, and unless you're actively developing on the developer portal itself locally, you should generally leave it unset as it disables most protections, including CORS.
148148

149+
### `edgeLambdaRebuildToken: string`
150+
151+
*Default: `'defaultRebuildToken'`*
152+
153+
Change this value if you want to update the edge lambda or its replicator lambda in the next deployment. In general, you shouldn't need to set it unless either 1. you're developing against the project and need to make changes to it, or 2. the project updated that part of the code and you just pulled its changes in preparation to update your deployment.
154+
155+
> Why is this not handled internally? At the time of writing, edge lambdas are difficult to delete due to how long it takes for all their replicas to delete, and you can't delete lambdas with active replicas. This process could take anywhere from a couple hours to several days (well past the largest timeout supported by Lambda), and neither CloudFront nor Lambda currently offer any hooks to know when all the replicas are gone. So edge lambda versions are only created, never deleted, by the template.
156+
>
157+
> For this reason, it's better to require the user to explicitly choose when to update the lambda, so that during development, you're not flooded with versions, and during production, you can be better aware of when things change (it's on your account, after all).
158+
149159
### `samTemplate: string`
150160

151161
*Default: `cloudformation/template.yaml` relative to the repo's root*

cloudformation/template.yaml

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -79,6 +79,11 @@ Parameters:
7979
Description: Provide a token different from the last deployment's token to re-upload the dev portal site's static assets. You can provide a timestamp or GUID on each deployment to always re-upload the assets.
8080
Default: 'defaultRebuildToken'
8181

82+
EdgeLambdaRebuildToken:
83+
Type: String
84+
Description: Provide a token different from the last deployment's token to update the edge lambda. You can provide a timestamp or GUID on each deployment to always update it.
85+
Default: 'defaultRebuildToken'
86+
8287
StaticAssetRebuildMode:
8388
Type: String
8489
Description: By default, a static asset rebuild doesn't overwrite custom-content. Provide the value `overwrite-content` to replace the custom-content with your local version. Don't do this unless you know what you're doing -- all custom changes in your s3 bucket will be lost.
@@ -1755,8 +1760,7 @@ Resources:
17551760
ServiceToken: !GetAtt CloudFrontSecurityHeadersLambda.Arn
17561761
Name: !Ref CloudFrontSecurityHeadersLambda
17571762
RoleArn: !GetAtt LambdaEdgeFunctionRole.Arn
1758-
# To force update this any time the lambda changes
1759-
RebuildToken: !Ref CloudFrontSecurityHeadersLambda.Version
1763+
RebuildToken: !Ref EdgeLambdaRebuildToken
17601764

17611765
CloudFrontEdgeReplicatorRole:
17621766
Type: AWS::IAM::Role

dev-portal/example-deployer.config.js

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -32,4 +32,8 @@ module.exports = {
3232
// cognitoDomainAcmCertArn: 'arn:aws:acm:us-east-1:123456789012:certificate/98765432-9876-9876-9876-987654321098',
3333
// useRoute53Nameservers: true,
3434
// feedbackEmail: '[email protected]',
35+
36+
// Toggle this any time the edge lambda or its replicator lambda need updated. You will be told in
37+
// the migration instructions to do so if you need to.
38+
// edgeLambdaResetToken: 'reset',
3539
}

dev-portal/example-dev-deployer.config.js

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -31,4 +31,9 @@ module.exports = {
3131

3232
// Set development mode for local use.
3333
developmentMode: true,
34+
35+
// Toggle this any time the edge lambda or its replicator lambda are updated. In general, unless
36+
// either you're modifying them yourself or they were changed upstream and you just pulled those
37+
// changes, you shouldn't need to do anything about this value.
38+
// edgeLambdaResetToken: 'reset',
3439
}

scripts/internal/deploy-template.js

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -30,6 +30,7 @@ module.exports = async () => {
3030
useRoute53Nameservers,
3131
staticAssetRebuildMode,
3232
developmentMode,
33+
edgeLambdaRebuildToken,
3334
awsSamCliProfile
3435
} = deployerConfig
3536

@@ -64,6 +65,7 @@ module.exports = async () => {
6465
...(customDomainName ? [`CustomDomainName=${customDomainName}`] : []),
6566
...(customDomainNameAcmCertArn ? [`CustomDomainNameAcmCertArn=${customDomainNameAcmCertArn}`] : []),
6667
...(useRoute53Nameservers ? [`UseRoute53Nameservers=${useRoute53Nameservers}`] : []),
68+
...(edgeLambdaRebuildToken ? [`EdgeLambdaRebuildToken=${edgeLambdaRebuildToken}`] : []),
6769
'--s3-bucket', buildAssetsBucket,
6870
...(awsSamCliProfile ? ['--profile', awsSamCliProfile] : [])
6971
])

scripts/internal/get-deployer-config.js

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -58,6 +58,7 @@ exports.customDomainNameAcmCertArn = getOptional('customDomainNameAcmCertArn')
5858
exports.useRoute53Nameservers = getOptional('useRoute53Nameservers')
5959
exports.staticAssetRebuildMode = getOptional('staticAssetRebuildMode')
6060
exports.developmentMode = getOptional('developmentMode')
61+
exports.edgeLambdaRebuildToken = getOptional('edgeLambdaRebuildToken')
6162

6263
// AWS SAM CLI configuration
6364
exports.awsSamCliProfile = getOptional('awsSamCliProfile')

0 commit comments

Comments
 (0)