question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

Unable to deploy new Lambda versions with AutoPublishAlias

See original GitHub issue

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!

Issue Analytics

  • State:closed
  • Created 4 years ago
  • Comments:5 (1 by maintainers)

github_iconTop GitHub Comments

1reaction
lisandrolancommented, Apr 10, 2020

Hey @jmnarloch , Could you provide more detail on how to use AutoPublishCodeSha256? I could not find much documentation and I having several errors with my template.

Im using all these properties: Properties: AutoPublishAlias: live AutoPublishCodeSha256: 1db85af3d9db8c7e63dfd243ef6751e665ffabc0452c172be5ab73b5004c2ce4

  ProvisionedConcurrencyConfig:
    ProvisionedConcurrentExecutions: 1
  DeploymentPreference:
    Type: AllAtOnce
0reactions
github-actions[bot]commented, Feb 5, 2022

We have noticed this issue has not received attention in 1 year. We will close this issue for now. If you think this is in error, please feel free to comment and reopen the issue.

Read more comments on GitHub >

github_iconTop Results From Across the Web

Deploying serverless applications gradually
Deploys new versions of your Lambda function, and automatically creates aliases that point to the new version. Gradually shifts customer traffic to the...
Read more >
Lambdas on AWS with CloudFormation error:"A version for ...
The error is not Cloudformation, it's Serverless telling CF to deploy a new lambda version, which is in fact the same one.
Read more >
AWS SAM and Lambda Aliases
While SAM does claim to support versioning and aliases, and even has a property called AutoPublishAlias that creates a new version and alias...
Read more >
AWS re:Post
Deployment at a single Lambda Alias update fails, but the lambda function that has the alias is different each time, even if no...
Read more >
Serverless AWS alias plugin
This plugin enables use of AWS aliases on Lambda functions. The term alias must not be mistaken as the stage. Aliases can be...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found