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

serverless.template file sometimes changes package type to Zip from Image #333

Open
benny-yamagata opened this issue Aug 13, 2024 · 5 comments
Assignees
Labels
bug This issue is a bug. module/cli-ext p2 This is a standard priority issue

Comments

@benny-yamagata
Copy link

benny-yamagata commented Aug 13, 2024

Describe the bug

Occasionally, after building the function locally I will notice a change in my source control tab in VS code for the serverless.template file. It will have changed my package type from image to zip and added additional fields to support it.

Nowhere else in my project is the word zip found, I'm wondering if this is some background process?

Expected Behavior

serverless.template does not change package type.

Current Behavior

serverless.template sometimes changes package type from image to zip. (does not happen the other way around)

Reproduction Steps

  1. dotnet new serverless.annotations
  2. Replace Functions.cs with the following:
/// <summary>
/// A collection of sample Lambda functions that provide a REST api for doing simple math calculations. 
/// </summary>
public class Functions
{
    [LambdaFunction()]
    public void ProcessDynamoDbEvent(DynamoDBEvent dynamoEvent, ILambdaContext context)
    {
        context.Logger.LogInformation("Processing event");
    
  1. Update serverless.template file to change PackageType to Image
  2. Add new class to bottom of Functions.cs
  3. Build the project

Possible Solution

No response

Additional Information/Context

No response

Targeted .NET platform

.net8

CLI extension version

Package Id                                     Version         Commands
----------------------------------------------------------------------------------------
amazon.lambda.tools                            5.9.0           dotnet-lambda

Environment details (OS name and version, etc.)

OSX Sonoma 14.6.1

@benny-yamagata benny-yamagata added bug This issue is a bug. needs-triage This issue or PR still needs to be triaged. labels Aug 13, 2024
@benny-yamagata
Copy link
Author

Updated description to include better repro steps

@bhoradc bhoradc added needs-reproduction This issue needs reproduction. module/cli-ext p2 This is a standard priority issue and removed needs-triage This issue or PR still needs to be triaged. labels Aug 13, 2024
@bhoradc bhoradc self-assigned this Aug 13, 2024
@bhoradc
Copy link

bhoradc commented Aug 13, 2024

Hi @benny-yamagata,

Thank you for reporting the issue. I am able to reproduce this scenario.

When I update the serverless.template file as below to change PackageType to Image, it reverts back to Zip type.

serverless.template

{
  "AWSTemplateFormatVersion": "2010-09-09",
  "Transform": "AWS::Serverless-2016-10-31",
  "Description": "An AWS Serverless Application.  This template is partially managed by Amazon.Lambda.Annotations (v1.3.0.0).",
  "Resources": {
    "LambdaToolsIssue333FunctionsProcessDynamoDbEventGenerated": {
      "Type": "AWS::Serverless::Function",
      "Metadata": {
        "Tool": "Amazon.Lambda.Annotations"
      },
      "Properties": {
        "MemorySize": 512,
        "Timeout": 30,
        "Policies": [
          "AWSLambdaBasicExecutionRole"
        ],
        "PackageType": "Image",
        "ImageUri": "."
      }
    }
  },
  "Outputs": {
    "ApiURL": {
      "Description": "API endpoint URL for Prod environment",
      "Value": {
        "Fn::Sub": "https://${ServerlessHttpApi}.execute-api.${AWS::Region}.amazonaws.com/"
      }
    }
  }
}

When I explicitly specify the PackageType in the LambdaFunction attribute as below, serverless.template file reflects the correct configuration for the Image packagetype and retains it.

[LambdaFunction(PackageType = LambdaPackageType.Image)]

I will further check on why manually updating the packagetype inside serverless.template doesn't work as expected.

Regards,
Chaitanya

@bhoradc bhoradc removed the needs-reproduction This issue needs reproduction. label Aug 13, 2024
@bhoradc
Copy link

bhoradc commented Aug 21, 2024

Hello @benny-yamagata,

I checked with the team to find out that the PackageType property must always be set via the Lambda Annotations attribute.

Any Lambda function property that can be set via the LambdaFunction attribute should be set via the attribute.

Therefore, using below setting would be the ideal way to update the default PackageType to Image.

[LambdaFunction(PackageType = LambdaPackageType.Image)]

And I can confirm that this configuration works as expected, kindly confirm if this helps.

Regards,
Chaitanya

@bhoradc bhoradc added response-requested Waiting on additional info and feedback. Will move to "closing-soon" in 7 days. and removed needs-review labels Aug 21, 2024
Copy link

github-actions bot commented Sep 1, 2024

This issue has not received a response in 5 days. If you want to keep this issue open, please just leave a comment below and auto-close will be canceled.

@github-actions github-actions bot added the closing-soon This issue will automatically close in 4 days unless further comments are made. label Sep 1, 2024
@benny-yamagata
Copy link
Author

Ok makes sense!

The other behavior should be documented somewhere, that if you dont set the annotation package type, it will always be changed. Otherwise it looks like phantom changes from nowhere.

@github-actions github-actions bot removed closing-soon This issue will automatically close in 4 days unless further comments are made. response-requested Waiting on additional info and feedback. Will move to "closing-soon" in 7 days. labels Sep 4, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug This issue is a bug. module/cli-ext p2 This is a standard priority issue
Projects
None yet
Development

No branches or pull requests

3 participants