Giter VIP home page Giter VIP logo

Comments (11)

jkellyinsf avatar jkellyinsf commented on May 28, 2024 2

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.

GavinZZ avatar GavinZZ commented on May 28, 2024

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.

github-actions avatar github-actions commented on May 28, 2024

⚠️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.

jkellyinsf avatar jkellyinsf commented on May 28, 2024

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.

GavinZZ avatar GavinZZ commented on May 28, 2024

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.

jkellyinsf avatar jkellyinsf commented on May 28, 2024

Both of those imply that I've previously copied the file up to s3 through some other means, right?

from serverless-application-model.

GavinZZ avatar GavinZZ commented on May 28, 2024

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.

jkellyinsf avatar jkellyinsf commented on May 28, 2024

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.

GavinZZ avatar GavinZZ commented on May 28, 2024

Thanks for the template. Assuming this is your directory setup, see screenshot below. Note that similar could apply to a zip as well.
Screenshot 2024-01-02 at 12 54 00 PM

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.

GavinZZ avatar GavinZZ commented on May 28, 2024

Thanks for the recommendation. I'm going to close this issue and open a ticket internally for doc update.

from serverless-application-model.

github-actions avatar github-actions commented on May 28, 2024

⚠️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)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo 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.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.