The ZipFile attribute is not supported for the runtime 'dotnet6'
Describe the bug
I am attempting to create a CloudFormation template to deploy structure to AWS from an Azure pipeline. Part of this is a Lambda function which we build in Azure and package using AWS Toolkit for Azure as a zip package.
When I attempt to deploy this through the template, the deployment fails and there is an event in the CloudFormation stack which states:
Resource handler returned message: "Invalid request provided: The ZipFile attribute is not supported for the runtime 'dotnet6'" (RequestToken: 81015358-9c36-911f-6482-5ad598f5d52a, HandlerErrorCode: InvalidRequest)
Expected Behavior
A successful deployment including a dot net 6 Lambda.
Current Behavior
I am attempting to deploy to AWS from an Azure Pipeline using the CloudFormationCreateOrUpdateStack@1 task.
CloudFormation Template snippet:
XXX:
Type: AWS::Lambda::Function
Properties:
Code:
ZipFile: '$(Pipeline.Workspace)/build-artifacts/XXX/XXX.zip'
Description: 'lorem ipsum'
Handler: 'XXX::XXX.Function::FunctionHandler'
MemorySize: 256
PackageType: Zip
Role: !Sub
- 'arn:aws:iam::${Account}:role/roleName'
- Account: !Ref TargetEnvironment
Runtime: dotnet6
Timeout: 30
The Lambda is created in C# using .NET 6 and packaged using AWS tools. It can be successfully deployed using other methods.
However, when attempting to deploy through CloudFormation, I receive the error:
Resource handler returned message: "Invalid request provided: The ZipFile attribute is not supported for the runtime 'dotnet6'" (RequestToken: 81015358-9c36-911f-6482-5ad598f5d52a, HandlerErrorCode: InvalidRequest)
Reproduction Steps
I am attempting to deploy to AWS from an Azure Pipeline using the CloudFormationCreateOrUpdateStack@1 task.
CloudFormation Template snippet:
XXX:
Type: AWS::Lambda::Function
Properties:
Code:
ZipFile: '$(Pipeline.Workspace)/build-artifacts/XXX/XXX.zip'
Description: 'lorem ipsum'
Handler: 'XXX::XXX.Function::FunctionHandler'
MemorySize: 256
PackageType: Zip
Role: !Sub
- 'arn:aws:iam::${Account}:role/roleName'
- Account: !Ref TargetEnvironment
Runtime: dotnet6
Timeout: 30
The Lambda is created in C# using .NET 6 and packaged using AWS tools. It can be successfully deployed using other methods.
However, when attempting to deploy through CloudFormation, I receive the error:
Resource handler returned message: "Invalid request provided: The ZipFile attribute is not supported for the runtime 'dotnet6'" (RequestToken: 81015358-9c36-911f-6482-5ad598f5d52a, HandlerErrorCode: InvalidRequest)
Possible Solution
No response
Additional Information/Context
No response
AWS .NET SDK and/or Package version used
I don't know what you want here. The Lambda has dependencies on Amazon.Lambda.Core 2.1.0, and Amazon.Lambda.Serialization.SystemTextJson 2.3.0.
Targeted .NET Platform
.NET 6
Operating System and version
We develop on WIndows 10 and are attempting to deploy the Lambda to Linux.
Similar issue https://github.com/aws-cloudformation/cloudformation-coverage-roadmap/issues/80 worked upon in the past by CloudFormation team. (for Ruby 2.7, existing open issue https://github.com/aws-cloudformation/cloudformation-coverage-roadmap/issues/951)
The ZipFile property is only supported for Node.JS and Python runtimes. The intention of the ZipFile is to embedded source and then CloudFormation/Lambda will automatically create a zip file from the embedded source. That works fine for dynamic languages but not static languages that require a build step.
With just using CloudFormation you would need to upload the zip file to S3 and then update the Code\S3Key and Code\S3Bucket properties to where you uploaded in S3.
An easier option might be to use the Amazon.Lambda.Tools CLI tool which you can install using the command dotnet tool -g amazon.lambda.tools. With the tool installed you can run in an earlier stage of your Azure pipeline the command
dotnet lambda package-ci --template <your-cf-template> --s3-bucket <bucket to stage zip files> --output-template <transformed-template>
This will take care of uploading all of the zips for each Lambda function declared in the CF template to S3. Then updated the CF template to the location in S3 where the zip files exist. The updated template will be saved in the file specified by the --output-template switch. Then push this new template through the pipeline and use that in the CloudFormationCreateOrUpdateStack task.
The package-ci command looks at the Code\S3Key property and if the path is pointing to a local folder with a .NET project it will build the project and zip up the output. If the Code\S3Key property is not set the directory where the CF template is at is assumed. If you want the build to happen by a previous stage in your pipeline and you only want this stage of the pipeline to work with zip files then have the Code\S3Key property be set to the relative path from the template to the where the zip file is locally. Then the package-ci command will take care of uploading the zip file and transforming the CF template.
Thanks for the information. Unfortunate to hear that .NET isn't supported in CloudFormation templates.
The documentation at https://docs.aws.amazon.com/AWSCloudFormation/latest/UserGuide/aws-resource-lambda-function.html#cfn-lambda-function-packagetype could be updated to indicate that only NodeJS and Python are supported. I don't see anything there which indicates this limitation.
@jarrodkoch Could you please use the Provide feedback to submit the documentation feedback? Also confirm if we could close this issue.
Yes and yes.
⚠️COMMENT VISIBILITY WARNING⚠️
Comments on closed issues are hard for our team to see. If you need more assistance, please either tag a team member or open a new issue that references this one. If you wish to keep having a conversation with other community members under this issue feel free to do so.