My question is based on this article. I found an issue when I have a .NET project referencing another project.
I added the Bundling Options like this.
var buildOption = new BundlingOptions()
{
Image = Runtime.DOTNET_6.BundlingImage,
User = "root",
OutputType = BundlingOutput.ARCHIVED,
Command = new string[] {
"/bin/sh",
"-c",
" dotnet tool install -g Amazon.Lambda.Tools"+
" && dotnet build"+
" && dotnet lambda package --output-package /asset-output/function.zip"
}
};
My goal:
- Automatically build the lambda code and zip the code when running:
cdk deploy
.
After I followed the article, I got these errors.
Bundling asset BervProjectMergePDFInfraStack/PdfMerger/Code/Stage...
You can invoke the tool using the following command: dotnet-lambda
Tool 'amazon.lambda.tools' (version '5.6.4') was successfully installed.
MSBuild version 17.3.2+561848881 for .NET
Determining projects to restore...
Skipping project "/BervProject.MergePDF.S3/BervProject.MergePDF.S3.csproj" because it was not found.
Skipping project "/BervProject.MergePDF.S3/BervProject.MergePDF.S3.csproj" because it was not found.
Restored /asset-input/BervProject.MergePDF.Lambda.csproj (in 9.22 sec).
/var/lang/bin/sdk/6.0.407/Microsoft.Common.CurrentVersion.targets(2066,5): warning : The referenced project '../../../BervProject.MergePDF.S3/BervProject.MergePDF.S3.csproj' does not exist. [/asset-input/BervProject.MergePDF.Lambda.csproj]
/asset-input/Startup.cs(2,28): error CS0234: The type or namespace name 'S3' does not exist in the namespace 'BervProject.MergePDF' (are you missing an assembly reference?) [/asset-input/BervProject.MergePDF.Lambda.csproj]
/asset-input/Startup.cs(3,28): error CS0234: The type or namespace name 'S3' does not exist in the namespace 'BervProject.MergePDF' (are you missing an assembly reference?) [/asset-input/BervProject.MergePDF.Lambda.csproj]
/asset-input/Functions.cs(13,26): error CS0246: The type or namespace name 'IMerger' could not be found (are you missing a using directive or an assembly reference?) [/asset-input/BervProject.MergePDF.Lambda.csproj]
/asset-input/Functions.cs(17,26): error CS0246: The type or namespace name 'IMerger' could not be found (are you missing a using directive or an assembly reference?) [/asset-input/BervProject.MergePDF.Lambda.csproj]
Build FAILED.
/var/lang/bin/sdk/6.0.407/Microsoft.Common.CurrentVersion.targets(2066,5): warning : The referenced project '../../../BervProject.MergePDF.S3/BervProject.MergePDF.S3.csproj' does not exist. [/asset-input/BervProject.MergePDF.Lambda.csproj]
/asset-input/Startup.cs(2,28): error CS0234: The type or namespace name 'S3' does not exist in the namespace 'BervProject.MergePDF' (are you missing an assembly reference?) [/asset-input/BervProject.MergePDF.Lambda.csproj]
/asset-input/Startup.cs(3,28): error CS0234: The type or namespace name 'S3' does not exist in the namespace 'BervProject.MergePDF' (are you missing an assembly reference?) [/asset-input/BervProject.MergePDF.Lambda.csproj]
/asset-input/Functions.cs(13,26): error CS0246: The type or namespace name 'IMerger' could not be found (are you missing a using directive or an assembly reference?) [/asset-input/BervProject.MergePDF.Lambda.csproj]
/asset-input/Functions.cs(17,26): error CS0246: The type or namespace name 'IMerger' could not be found (are you missing a using directive or an assembly reference?) [/asset-input/BervProject.MergePDF.Lambda.csproj]
1 Warning(s)
4 Error(s)
Time Elapsed 00:00:14.36
Unhandled exception. System.Exception: Failed to bundle asset BervProjectMergePDFInfraStack/PdfMerger/Code/Stage, bundle output is located at D:\Projects\Github\MergePDFOnline\cdk.out\asset.8002390a958718ff5743fdca447ec443297b0f1ed8dc390b1c49e2e8cbb60427-error: Error: docker exited with status 1
at Amazon.JSII.Runtime.Services.Client.TryDeserialize[TResponse](String responseJson)
at Amazon.JSII.Runtime.Services.Client.ReceiveResponse[TResponse]()
at Amazon.JSII.Runtime.Services.Client.Send[TRequest,TResponse](TRequest requestObject)
at Amazon.JSII.Runtime.Services.Client.Create(CreateRequest request)
at Amazon.JSII.Runtime.Services.Client.Create(String fullyQualifiedName, Object[] arguments, Override[] overrides, String[] interfaces)
at Amazon.JSII.Runtime.Deputy.DeputyBase..ctor(DeputyProps props)
at Constructs.Construct..ctor(DeputyProps props)
at Amazon.CDK.Resource..ctor(DeputyProps props)
at Amazon.CDK.AWS.Lambda.FunctionBase..ctor(DeputyProps props)
at Amazon.CDK.AWS.Lambda.Function..ctor(Construct scope, String id, IFunctionProps props)
at BervProject.MergePDF.Infra.BervProjectMergePDFInfraStack..ctor(Construct scope, String id, IStackProps props) in D:\Projects\Github\MergePDFOnline\BervProject.MergePDF.Infra\BervProjectMergePDFInfraStack.cs:line 32
at BervProject.MergePDF.Infra.Program.Main(String[] args) in D:\Projects\Github\MergePDFOnline\BervProject.MergePDF.Infra\Program.cs:line 13
I think the build process is not running in the lambda project directory, so the process failed.
Do you have another solution or alternative at least I can ensure the lambda will be deployed correctly. My current condition is the Lambda doesn't have any assemblies yet.
If you need more details about my code is here.
Thank you! This is what I'm looking for. I just realized I only define the project path without the dependencies.
Can you expand your answer with code snippets? I changed the path to the .sln folder, but then I got this error:
I tried to specify Exclude for
.vs
but it does not work.After I close Visual Studio, I get another error: