Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Provide passthrough Code property for AWS::Serverless::Function. #3358

Closed
garretwilson opened this issue Sep 28, 2023 · 7 comments
Closed

Provide passthrough Code property for AWS::Serverless::Function. #3358

garretwilson opened this issue Sep 28, 2023 · 7 comments
Labels
blocked/more-info-needed More info is needed from the requester. If no response in 14 days, it will become stale. type/feature

Comments

@garretwilson
Copy link

SAM's AWS::Serverless::Function removes the ability to use imported values in referring to the bucket and filename of my uploaded ZIP file for AWS Lambda. This is an inherent issue with the SAM transform design; see e.g. #2533 and a long comment in another ticket explaining all the gory details.

As explained in detail in #3264, I can do the following just fine using AWS::Lambda::Function, which uses Code instead of CodeUri. It looks like this:

      Code:
        S3Bucket:
          Fn::ImportValue:
            !Sub "other-stack-${env}:stagingBucket"
        S3Key: !Sub "foo-${ver}-aws-lambda.zip"

But I can't do that with AWS::Serverless::Function:

      CodeUri: !Sub
        - "s3://${bucket}/foo-${ver}-aws-lambda.zip"
        - bucket: my-staging-bucket
            Fn::ImportValue:
              !Sub "other-stack-${env}:stagingBucket"

That produces:

Error: Failed to create changeset for the stack: my-stack, ex: Waiter ChangeSetCreateComplete failed: Waiter encountered a terminal failure state: For expression "Status" we matched expected path: "FAILED" Status: FAILED. Reason: Transform AWS::Serverless-2016-10-31 failed with: Invalid Serverless Application Specification document. Number of errors found: 1. Resource with id [MyFunction] is invalid. 'CodeUri' requires Bucket and Key properties to be specified.

Please add a Code pass-through property to AWS::Serverless::Function so we can at least work around this shortcoming in the design of SAM.

@garretwilson garretwilson added the stage/needs-triage Automatically applied to new issues and PRs, indicating they haven't been looked at. label Sep 28, 2023
@GavinZZ
Copy link
Contributor

GavinZZ commented Sep 28, 2023

Hi thanks for creating a issue. I apologize for the trouble you've been through. I'll bring it up for discussion with the team and get back to you soon.

@GavinZZ
Copy link
Contributor

GavinZZ commented Sep 29, 2023

Hi @garretwilson, I've brought this up to the team and we're having discussion on potential workaround/solution. Meanwhile I just want to quickly confirm that you've also tried with the following syntax and it doesn't work for you.

  CodeUri:
    Bucket:
      Fn::ImportValue:
        !Sub "other-stack-${env}:stagingBucket"
    Key: !Sub "foo-${ver}-aws-lambda.zip"

@GavinZZ GavinZZ added blocked/more-info-needed More info is needed from the requester. If no response in 14 days, it will become stale. type/feature and removed stage/needs-triage Automatically applied to new issues and PRs, indicating they haven't been looked at. labels Sep 29, 2023
@garretwilson
Copy link
Author

Well I'd like to answer your question, but suddenly SAM is doing all sorts of crazy things, as I just reported in aws/aws-sam-cli#6014. (Sigh. If it's not one thing, it's another thing breaking.)

@garretwilson
Copy link
Author

garretwilson commented Sep 29, 2023

@GavinZZ , I have wonderful news! (Note that the SAM traceback in aws/aws-sam-cli#6014 is still happening, but it doesn't seem to impede the actual deployment.) The format you asked about worked:

  CodeUri:
    Bucket:
      Fn::ImportValue:
        !Sub "other-stack-${env}:stagingBucket"
    Key: !Sub "foo-${ver}-aws-lambda.zip"

It seems that CodeUri allows not only a String but also a FunctionCode object, the latter of which has a Bucket and a Key. These seems to be passthrough properties for CloudFormation S3Bucket and S3Key. Yay! 🎉 Just what I need.

I wonder why nobody mentioned this during the long discussion in #3264? 🤔

Is the CodeUri > FunctionCode type new for SAM, or has it always been there?

@GavinZZ
Copy link
Contributor

GavinZZ commented Sep 29, 2023

Great to hear that and hopefully this syntax will unblock you. 🎉🎉🎉

CodeUri supported both String syntax and FunctionCode object syntax and it's always been this way.

@GavinZZ
Copy link
Contributor

GavinZZ commented Sep 29, 2023

Going to mark this issue as resolved. Feel free to re-open if you have any additional questions.

@GavinZZ GavinZZ closed this as completed Sep 29, 2023
@garretwilson
Copy link
Author

'CodeUri' supported both 'String' syntax and 'FunctionCode' object syntax and it's always been this way.

In that case, feel free to close this current ticket as "invalid", because SAM already has exactly what I was requesting!

Note also that #3264 therefore doesn't impact me, since I can always use the passthrough properties.

I'm so happy to find this out. Thanks for taking the time to suggest that.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
blocked/more-info-needed More info is needed from the requester. If no response in 14 days, it will become stale. type/feature
Projects
None yet
Development

No branches or pull requests

2 participants