dotnet lambda publish-layer --region <AWS_REGION> --layer-name QueueHelperLayer --layer-type runtime-package-store -sb <S3_BUCKETNAME> -f netcoreapp2.1
- artifact.xml - packages.zip
As you can see, the QueueHelperLibrary package along with the other dependencies have been packaged into a layer.
Now you might wonder, why did I have to create an entirely new Lambda solution just to throw it all away. It doesn’t actually have to be that way. You just need to create a .xml file with the list of NuGet packages that need to be created into a Layer. The format of the XML file should be as below.
<StoreArtifacts> <Package Id="<NUGET_PACKAGE>" Version="<VERSION>" /> </StoreArtifacts>
In our case, you could have a file that looks like the one below and push create the Lambda Layer by adding the additional -package-manifest parameter
<StoreArtifacts> <Package Id="QueueHelperLibrary" Version="1.2.0" /> </StoreArtifacts>
dotnet lambda publish-layer --region <AWS_REGION> --layer-name QueueHelperLayer --layer-type runtime-package-store -sb <S3_BUCKETNAME> -f netcoreapp2.1 --package-manifest <XML_FILENAME>
- Change the profile parameter to your AWS profile name on the local machine - Change the function-layers parameter to the ARN of the Lambda Layer you just created - Change the function-role parameter to the ARN of the IAM role you created earlier - Change the s3-bucket parameter to the name of the S3 bucket you created earlier
Navigate to the S3 bucket where the Lambda function is stored. When you download the package.zip file, you will see that there is just one library in the package. Other libraries will be obtained from the Lambda Layer that is configured to the Lambda function. Given that there is a cap of 75GB of storage limit per account for Lambda, using Layers will allow you to have increased number of functions deployed due to lower storage requirements.