Skip to content

Unable to deploy new Lambda versions with AutoPublishAlias #97

@scionwest

Description

@scionwest

I have a serverless template that has AutoPublishAlias set to the environment name I'm deploying into.

I need to have AutoPublishAlias set in order to use ProvisionedConcurrencyConfig. However, I can't control the version number of the published Lambda from the serverless resource type. The docs say:

This AWS SAM property generates two additional resources: an AWS::Lambda::Version resource and an AWS::Lambda::Alias resource.

Since this generates the two additional resources, I'm not able to specify the version number of the Lambda. After I've run dotnet lambda deploy-serverless I am unable to run it a second time as a Lambda already exists with the same version number. I don't really want the Alias to change, just the version of the Alias.

Note: I'm not using Alias to differentiate environments. Dedicated Lambda's are deployed per environment as the resource name includes the environment name. As environment parameter changes, the resource names will as well.

For a working example, you can clone my feature branch and perform the following steps:

  • Create S3 bucket called focusmark-dev-deployments
  • Run dotnet lambda publish-layer FocusMarkApiProjectsLayer --layer-type runtime-package-store --s3-bucket focusmark-dev-deployments from the FocusMark/src/FocusMark.Api.Projects directory
  • Update the aws-lambda-tools-defaults.json file by changing the LambdaApiLayers template-parameter with the ARN of the deployed layer above.
  • Run dotnet lambda deploy-serverless from the FocusMark/src/FocusMark.Api.Projects directory

When completed, change the provisioned concurrency configuration from 2 to 3 and re-run dotnet lambda deploy-serverless. The error will report:

A version for this Lambda function exists ( 1 ). Modify the function to create a new version.

My understanding of how the version number is created is that it generates a hash of the CodeUri & function logical-id. I'm not pre-deploying the Lambda into S3, it's being deployed by the CLI extension. When I download the template pushed to S3 by the CLI, I see the CodeUri is set to s3://<obfuscated-bucket>/<obfuscated-path>/CreateProjectCommand-CodeUri-637114132146239023-637114132179701965.zip and it changes with each deployment. This should be sufficient for creating a unique hash with each deployment.

What I think is happening is that my source code isn't changing, just the template in this case as I want to increase the provisioned concurrency. CloudFormation then fails because the version number hash is the same as the code wasn't re-deployed. I don't want to make small changes to the code all the time just to force a new source deployment if that is the case. Are there any recommended work-arounds?

Thanks for any guidance on this!

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions