Comments (11)
Okay, that's a possible workaround. To back up a bit, there were various workarounds suggested in 5249 and similar issues. Other ones included writing a sed script that pre-processes the template.yaml. Or synching the zip file myself up to s3 before calling sam deploy, which would let me point to an s3 location in the CodeUri, in which case !Sub interpolation would work. Or bypassing sam entirely and writing a base CF template.yaml.
I appreciate all the options. My request in this ticket was for you guys to figure out an official recommendation for this use case and put it in the docs. Your recommendation might be "here are three possible workarounds" or a clear statement that sam doesn't support a dynamically constructed CodeUri pointing to a local artifact, so we can either use versioned artifacts, or we can use sam to sync automatically to s3, but we can't use both.
from serverless-application-model.
Hi @jkellyinsf, thanks for cutting an issue. AWS::Serverless::Function
supports two ways of defining the CodeUri
property (see link). One simple way to define the versioning property is documented here.
An example of CodeUri
property with versioning is provided here:
CodeUri:
Bucket: mybucket-name
Key: mykey-name
Version: 121212
Going to mark this issue as closed. Feel free to re-open it if you have additional questions.
from serverless-application-model.
⚠️ COMMENT VISIBILITY WARNING⚠️
Comments on closed issues are hard for our team to see.
If you need more assistance, please either tag a team member or open a new issue that references this one.
If you wish to keep having a conversation with other community members under this issue feel free to do so.
from serverless-application-model.
Thanks for the quick response, @GavinZZ. I'm not using a version-enabled S3 bucket and desiring to point to a previous s3 version of an artifact.
The artifact is on my local machine and has a version number in its filename. I want to specify in CodeUri a local file path string with the version number interpolated dynamically using !Sub. And I want sam deploy to sync the artifact to S3 as it does when the file path is a constant string. But instead that gives errors that CodeUri is not a valid s3 path.
I cannot re-open the issue.
from serverless-application-model.
Re-opened the issue. Apologize that I misinterpret it initially. To address the issue you mentioned, there're two potential solutions.
One is to use the format I suggested but changed it to something like this
CodeUri:
Bucket: mybucket-name
Key: !Sub 'foo-bar-functions-${Ver}.jar' # assuming Ver is a template parameter
Alternatively, you can use what's discussed in aws/aws-sam-cli#5249.
The SAM template still requires AWS::LanguageExtensions:
Transform:
- AWS::LanguageExtensions
- AWS::Serverless-2016-10-31
Resources:
TestIngestFunction:
Type: AWS::Serverless::Function
Properties:
CodeUri: !Sub "s3://my-sam-bucket/foo-bar-functions-${Ver}.jar"
Personally, I would recommend the first solution as it's cleaner and it doesn't require the use of an additional transform.
from serverless-application-model.
Both of those imply that I've previously copied the file up to s3 through some other means, right?
from serverless-application-model.
In the second solution I mentioned above, you can instead point to a local file with !Sub
intrinsics if that's what you need.
If that's not what you want, would you kindly provide a template/example to help me understand the problem.
from serverless-application-model.
Version functions rather than artifacts? That's an idea that's probably more feasible in python than it is in java. Here's an example:
Parameters:
Version:
Type: String
Default: "1.2.17"
MyLambdaFunction:
Type: AWS::Serverless::Function
Properties:
FunctionName: MyLambda
CodeUri: !Sub "build/artifacts/my-service-${Version}.zip"
Handler: org.me.MyLambdaImpl
Runtime: java17
from serverless-application-model.
Thanks for the template. Assuming this is your directory setup, see screenshot below. Note that similar could apply to a zip as well.
This is how to point to a file with version number.
Transform: AWS::Serverless-2016-10-31
Parameters:
Ver:
Type: String
Default: '1'
Resources:
HelloWorldFunction:
Type: AWS::Serverless::Function # More info about Function Resource: https://github.com/awslabs/serverless-application-model/blob/master/versions/2016-10-31.md#awsserverlessfunction
Properties:
CodeUri: HelloWorldFunction/
Handler: !Sub 'helloworld.App_${Ver}::handleRequest' # Intrinsics to point to the correct file+handler
Runtime: java8
Architectures:
- x86_64
MemorySize: 512
from serverless-application-model.
Thanks for the recommendation. I'm going to close this issue and open a ticket internally for doc update.
from serverless-application-model.
⚠️ COMMENT VISIBILITY WARNING⚠️
Comments on closed issues are hard for our team to see.
If you need more assistance, please either tag a team member or open a new issue that references this one.
If you wish to keep having a conversation with other community members under this issue feel free to do so.
from serverless-application-model.
Related Issues (20)
- "Invalid OpenAPI input" when OpenAPI set to `3.1.0` HOT 4
- AWS SAM Connector Write needs PutObjectTagging HOT 2
- Setting the runtime of a function to nodejs20.x causes sam validate to fail. HOT 2
- AWS::Serverless::Api - setting "OpenApiVersion" causes "Stage" deployment to be skipped - why? HOT 6
- [Test] GitHub Action automatic comments on GitHub closed Issue HOT 1
- AlwaysDeploy does not include GatewayResponse updates HOT 7
- Bug: AWS::Serverless::Function Policies partly not applied HOT 8
- Cors error from SAM template and Auth enabled. HOT 3
- VSCode SAM Schema Validation Error with !Ref in Conditions Section HOT 7
- Bug: Creates unnecessary AWSLambdaVPCAccessExecutionRole role HOT 7
- Api CORS issue with 500 status after setup Cognito authorizer HOT 3
- Building features for AWS SAM HOT 4
- Can't reset BinaryMediaTypes to a default value for API Gateway REST API HOT 2
- 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
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.