I have a CloudFront distribution with a single function:
CloudFrontDistribution:
Type: AWS::CloudFront::Distribution
Properties:
DistributionConfig:
…
DefaultCacheBehavior:
…
FunctionAssociations:
- EventType: viewer-request
FunctionARN: !GetAtt FooFunction.FunctionMetadata.FunctionARN
I deploy the stack using aws cloudformation deploy …
and see that in the console the FooFunction
has a status of Deployed
.
I define another function in the CloudFormation template and call aws cloudformation deploy …
again.
CloudFrontDistribution:
Type: AWS::CloudFront::Distribution
Properties:
DistributionConfig:
…
DefaultCacheBehavior:
…
FunctionAssociations:
- EventType: viewer-request
FunctionARN: !GetAtt FooFunction.FunctionMetadata.FunctionARN
- EventType: viewer-request
FunctionARN: !GetAtt BarFunction.FunctionMetadata.FunctionARN
Note that both functions have AutoPublish: true
set.
In the console both functions now appear under "Functions". The status of FooFunction
still shows Deployed
. However the status of BarFunction
is Published
. And if I click on BarFunction
, under "Associated distributions" it says:
This function is not associated with any distributions.
Yet it is clearly listed under FunctionAssociations
in the CloudFormation template.
I've tried almost everything to try to get around this. Most recently I even deleted both functions.
FunctionAssociations
section of the distribution.aws cloudformation deploy …
and then verified in the console that both functions no longer exist./*
) distribution from the console.FunctionAssociations
.aws cloudformation deploy
.I get back two functions:
FooFunction
: Deployed
BarFunction
: Published
Somehow AWS remembered these two functions, even though they were supposedly completely deleted, and only associated one of them with the distribution, when the configurations for both are identical in the template.
Why is CloudFormation associating only one function with the distribution and not both, and remembering which was associated with the distribution and which was not even after deleting them?
I opened CloudFormation CLI Issue #991 to report this, but I'm asking here in hopes it's just something simple I'm doing wrong. That ticket explains all the other workarounds I've tried. There seems to be no way to have two functions deployed at the same time, even though they are both listed in the FunctionAssociations
section.
I think your problem here is that both functions are associated to the same distribution, event type and cache behavior.
Per the docs restrictions on all edge functions
For a given cache behavior, the following restrictions apply:
Each event type (viewer request, origin request, origin response, and viewer response) can have only one edge function association.
Based on your CFN it appears that you are associating both viewer-request functions to the same Default Cache Behavior.
If you want both of them deployed then you need to associate each function to different event types and/or different cache behaviors.