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

Fixed an issue where CodeUri set in Globals section is ignored for AWS::Serverless::Function resource. #324

Merged
merged 1 commit into from
Jul 3, 2024

Conversation

ashishdhingra
Copy link
Contributor

@ashishdhingra ashishdhingra commented Jun 25, 2024

Issue #, if available: #119

Description of changes:
Fixed an issue where CodeUri set in Globals section is ignored for AWS::Serverless::Function resource. Refer Globals section of the AWS SAM template for details.

Testing:
Tested locally using the customer provided sample https://github.com/drch-/dotnet-sam-repro in issue #119.
Used Visual Studio debugging,

  • Setting the current directory for Amazon.Lambda.Tools the above repo's local directory.
  • Used deploy-serverless --template ./serverless-global.template.yml command line argument for using both the templates.

RESULT:

  • Before making the fix, the CodeUri set in serverless-global.template.yml in Globals section was not used.
  • After making the fix, the CodeUri set in serverless-global.template.yml in Globals section was used.

Kindly note that during deployment, the updated template is uploaded to S3 bucket. In the uploaded template, CodeUri in Globals section is not updated. Instead CodeUri for function resources is updated. Below is the example:

AWSTemplateFormatVersion: "2010-09-09"
Transform: "AWS::Serverless-2016-10-31"
Globals:
  Function:
    Runtime: dotnetcore3.1
    MemorySize: 256
    Timeout: 30
    CodeUri: ./func
Resources:
  UpperFunction:
    Type: AWS::Serverless::Function
    Properties:
      Handler: func::func.Function::UpperHandler
      CodeUri: s3://testbucket-issue1880/UpperFunction-CodeUri-Or-ImageUri-638549218961943105-638549219097951808.zip
  LowerFunction:
    Type: AWS::Serverless::Function
    Properties:
      Handler: func::func.Function::LowerHandler
      CodeUri: s3://testbucket-issue1880/UpperFunction-CodeUri-Or-ImageUri-638549218961943105-638549219097951808.zip
Outputs:
  upperFuncName:
    Value: !Ref UpperFunction
  lowerFuncName:
    Value: !Ref LowerFunction

By submitting this pull request, I confirm that my contribution is made under the terms of the Apache 2.0 license.

@ashishdhingra ashishdhingra requested a review from normj June 25, 2024 21:27
@ashishdhingra ashishdhingra added feature-request A feature should be added or improved. module/cli-ext p2 This is a standard priority issue labels Jun 26, 2024
Copy link
Member

@ashovlin ashovlin left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

  1. Could you either add automated test coverage for this, or at least write about how you tested it in the description?
  2. Don't we overwrite CodeUri with the S3 location once we upload the artifact? If so, does that work well in the Globals block?
    field.SetS3Location(this.S3Bucket, updateResults.S3Key);

@ashishdhingra
Copy link
Contributor Author

ashishdhingra commented Jul 2, 2024

  1. Could you either add automated test coverage for this, or at least write about how you tested it in the description?
  2. Don't we overwrite CodeUri with the S3 location once we upload the artifact? If so, does that work well in the Globals block?
    field.SetS3Location(this.S3Bucket, updateResults.S3Key);

@ashovlin Thanks for the review. Below are my inputs:

  • Updated description on how I tested it locally.
  • Yes, we overwrite CodeUri with the S3 location once we upload the artifact. The issue here is that customer wants to use the global CodeUri as local path to the function. This is used during packaging and upload the packaged code to S3 bucket. Once the result is processed, we update the CodeUri with S3 location so that CloudFormation could take over.
    Kindly note that the updated template is uploaded to S3 bucket. CodeUri in Globals section is not updated. Instead CodeUri for function resources is updated. Below is the example:
    AWSTemplateFormatVersion: "2010-09-09"
    Transform: "AWS::Serverless-2016-10-31"
    Globals:
      Function:
        Runtime: dotnetcore3.1
        MemorySize: 256
        Timeout: 30
        CodeUri: ./func
    Resources:
      UpperFunction:
        Type: AWS::Serverless::Function
        Properties:
          Handler: func::func.Function::UpperHandler
          CodeUri: s3://testbucket-issue1880/UpperFunction-CodeUri-Or-ImageUri-638549218961943105-638549219097951808.zip
      LowerFunction:
        Type: AWS::Serverless::Function
        Properties:
          Handler: func::func.Function::LowerHandler
          CodeUri: s3://testbucket-issue1880/UpperFunction-CodeUri-Or-ImageUri-638549218961943105-638549219097951808.zip
    Outputs:
      upperFuncName:
        Value: !Ref UpperFunction
      lowerFuncName:
        Value: !Ref LowerFunction

@ashishdhingra ashishdhingra requested a review from ashovlin July 2, 2024 20:30
@ashishdhingra ashishdhingra merged commit 6f68cd4 into dev Jul 3, 2024
2 checks passed
@ashishdhingra ashishdhingra deleted the user/ashdhin/GlobalCodeUri-Issue119 branch July 3, 2024 16:42
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
feature-request A feature should be added or improved. module/cli-ext p2 This is a standard priority issue
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants