Comments (7)
Hi @zhanzhenzhen, thanks for reporting the issue. After chatting with the SAM team, this seems like a known issue. I am transferring the ticket to their repo for the SAM team to provide more context and any workaround.
from serverless-application-model.
Hi @zhanzhenzhen,
As @hnnasit mentioned we are currently aware of this issue. Here is some context and a workaround:
Context + Root cause
The reason the AutoPublishAliasAllProperties property is not picking up the changes to the Layers property is because of the specific ordering that we have when transforming the resources listed in a SAM template. The current implementation will translate all AWS::Serverless::Functions
before translating the AWS::Serverless::LayerVersion
. Because the Serverless::Function
is translated first, the !Ref
to the Serverless::LayerVersion
will not have changed yet - that changes after we transform the LayerVersion
but by then it won't go back to transform the Serverless::Function
a second time.
Because SAM doesn't resolve intrinsics, we wouldn't necessarily consider this a bug, but we can definitely understand that it is not a great experience for our customers.
To address this issue with a fix, we would have to change the order in which resources are transformed which could result in unintended consequences. We have broken existing templates in the past so we try to tread carefully when making changes like this where it is difficult to estimate the full impact it would have on other customers.
Workaround
As a workaround, you can pass a combined shasum
of the .zip
used for the LayerVersion's ContentUri
+ the Lambda function code to the AutoPublishCodeSha256
property. This means that whenever the lambda or the referenced layer is changed then a new lambda version will be created.
shasum ~/.../layer.zip
26babb64f2c18e1a845cbdb684e6ef2f99319773 /.../Downloads/layer.zip
The combined shasum can be passed in as a global paramater:
Parameters:
AutoDeployVersion:
Type: String
Resources:
HelloWorldFunction:
Type: AWS::Serverless::Function
Properties:
...
AutoPublishAlias: foo
AutoPublishAliasAllProperties: True
AutoPublishCodeSha256: !Ref AutoDeployVersion
Layers:
- !Ref TestEnvLayer
and this can be set with the --parameters AutoDeployVersion="sha value"
flag through the CLI deployment command you are using.
Please give this a try and let me know if you have any other questions!
from serverless-application-model.
@paulhcsun Thank you for providing the workaround. Could you explain this in more detail:
a combined shasum of the .zip used for the LayerVersion's ContentUri + the Lambda function code
I usually only use sam build
and sam deploy
commands. Could you tell me how to generate the layer.zip
file? I looked into sam deploy
but cannot find --parameters
. Do you mean --parameter-overrides
?
from serverless-application-model.
Because the
Serverless::Function
is translated first, the!Ref
to theServerless::LayerVersion
will not have changed yet - that changes after we transform theLayerVersion
but by then it won't go back to transform theServerless::Function
a second time.
But why it updates the layer version when the function is not using alias?
from serverless-application-model.
Sorry yes, --parameter-overrides
is the correct flag. And ah my bad, the layer.zip
is from a previous issue that I used this workaround for. In your case you could just the shasum
command for your layer/layer.mjs
file.
If you are just manually deploying and want a simpler workaround, you could just add a Description
property to your Function
and manually change the value there when you want to deploy a new Lambda Version which should be picked up by the AutoPublishAliasAllProperties
.
But why it updates the layer version when the function is not using alias?
I'm not quite sure I follow your question here, could you elaborate what you mean?
from serverless-application-model.
I'm not quite sure I follow your question here, could you elaborate what you mean?
It seems that if a lambda function isn't deployed with AutoPublishAlias
or AutoPublishAliasAllProperties
, it's synced with new layer versions. I don't know why.
from serverless-application-model.
Oh that's interesting, I'll try to investigate why that happens but at the moment I'm also not sure why it would properly sync with new layer versions if those properties are not specified.
I'll move this into Discussion to collect more feedback from anyone facing this issue in the meantime.
from serverless-application-model.
Related Issues (20)
- AWS::Serverless::Api auto deploys API when a resource is being added HOT 4
- Environment variables not updated HOT 5
- Bug: Using a Ref in StageName is Not Working Properly - Template.yaml HOT 4
- !If not working on Serverless:Function handler HOT 5
- how to configure KMSVerifyPolicy and KMSSignPolicy HOT 1
- Feature request: Git sync HOT 4
- Security: default permission allow any service to invoke a lambda function HOT 3
- Several tests fail with Pydantic 1.10.15 (latest 1.x) HOT 6
- (New Connector Profile) AWS Batch HOT 1
- EventInvokeConfig does not appear in processed template when following the spec HOT 3
- (New Connector Profile) AWS::ApiGateway::RestApi > AWS::Serverless::StateMachine HOT 1
- Several tests fail with Pydantic 1.10.17 (latest 1.x) HOT 5
- Bug: No new Lambda Versions are deployed with Lambda configurations changes HOT 6
- Event sources do not invoke versioned state machines by their alias HOT 4
- Lambda layer code not updated in Lambda function during `sam sync` HOT 1
- SQS:*Batch permissions aren't vaild permissions HOT 2
- Can't use ForEach intrinsic function to define resources HOT 6
- Set Pydantic 2.* as possible dependency HOT 2
- Library usage and Default values
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
D3
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
-
Recommend Topics
-
javascript
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
-
web
Some thing interesting about web. New door for the world.
-
server
A server is a program made to process requests and deliver data to clients.
-
Machine learning
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from serverless-application-model.