aws / aws-sam-cli

CLI tool to build, test, debug, and deploy Serverless applications using AWS SAM
https://aws.amazon.com/serverless/sam/
Apache License 2.0
6.5k stars 1.17k forks source link

Sam build with project references in adjacent directory (.NET8 NativeAOT) #7321

Closed kyl3t closed 1 month ago

kyl3t commented 1 month ago

Hi, I have a question regarding running sam build on a .NET 8 Serverless NativeAOT project with project references referencing an adjacent directory.

My project structure is as below, building worked fine when building only the Cwoc.Lambda project but ever since including shared projects from the shared folder, the docker run command that is eventually called is not able to locate these files as they aren't mounted.

Please let me know of any workarounds or options to address this. Thanks

.
└── src/
    ├── apps/
    │   └── Cwoc/
    │       ├── Cwoc.sln
    │       └── Cwoc.Lambda/
    │           ├── serverless.yaml
    │           └── ...
    └── shared/
        ├── CA.C7.API
        ├── CA.Email
        └── ...
sam build --template ./apps/Cwoc/Cwoc.Lambda/serverless.yaml
Building codeuri: /Users/kt/Source/custom/src/apps/Cwoc/Cwoc.Lambda runtime: dotnet8 metadata: {'Tool': 'Amazon.Lambda.Annotations'} architecture: arm64 functions:                                              
CwocLambdaFunctionsOrderTxHandlerGenerated, CwocLambdaFunctionsOrderRxHandlerGenerated, CwocLambdaFunctionsStockSyncHandlerGenerated                                                                  
Workflow DotnetCliPackageBuilder does not support value "False" for building in source. Using default value "True".                                                                                                                                                     
 Running DotnetCliPackageBuilder:GlobalToolInstall                                                                                                                                                                                                                      
Tool 'amazon.lambda.tools' was reinstalled with the stable version (version '5.10.7').                                                                                                                                                                                  
 Running DotnetCliPackageBuilder:RunPackageAction                                                                                                                                                                                                                       
Amazon Lambda Tools for .NET Core applications (5.10.7)                                                                                                                                                                                                                 
Project Home: https://github.com/aws/aws-extensions-for-dotnet-cli, https://github.com/aws/aws-lambda-dotnet                                                                                                                                                            

Executing publish command                                                                                                                                                                                                                                               
Starting container for native AOT build using build image: public.ecr.aws/sam/build-dotnet8:latest-arm64.                                                                                                                                                               
... invoking 'docker run --name tempLambdaBuildContainer-6e26ef82-2544-427d-83cd-b3d780edf5e1 --rm --volume "/Users/kt/Source/custom/src/apps/Cwoc":/tmp/source/ -i -u 501:20 -e DOTNET_CLI_HOME=/tmp/dotnet -e XDG_DATA_HOME=/tmp/xdg 
public.ecr.aws/sam/build-dotnet8:latest-arm64 dotnet publish "/tmp/source/Cwoc.Lambda" --output "/tmp/source/Cwoc.Lambda/bin/Release/net8.0/publish" --configuration "Release" --framework "net8.0" --runtime linux-arm64   
/p:GenerateRuntimeConfigurationFiles=true --self-contained True  /p:StripSymbols=true' from directory /Users/kt/Source/custom/src/apps/Cwoc                                                                                            
... docker run: An issue was encountered verifying workloads. For more information, run "dotnet workload update".                                                                                                                                                       
... docker run:   Determining projects to restore...                                                                                                                                                                                                                    
... docker run:   Skipping project "/shared/CA.C7.API/CA.C7.API.csproj" because it was not found.                                                                                                                                                   
... docker run:   Skipping project "/shared/CA.Protocols.SFTP/CA.Protocols.SFTP.csproj" because it was not found.                                                                                                                                       
... docker run:   Skipping project "/shared/CA.C7.API/CA.C7.API.csproj" because it was not found.                                                                                                                                                   
... docker run:   Skipping project "/shared/CA.Protocols.SFTP/CA.Protocols.SFTP.csproj" because it was not found.                                                                                                                                       
... docker run:   Restored /tmp/source/Cwoc/Cwoc.csproj (in 4.07 sec).                                                                                                                                                      
... docker run:   Restored /tmp/source/Cwoc.Lambda/Cwoc.Lambda.csproj (in 8.59 sec).                                                                                                                                        
... docker run: /var/lang/bin/sdk/8.0.303/Microsoft.Common.CurrentVersion.targets(2165,5): warning : The referenced project '../../../shared/CA.C7.API/CA.C7.API.csproj' does not exist.                                                            
[/tmp/source/Cwoc/Cwoc.csproj]                                                                                                                                                                                              
... docker run: /var/lang/bin/sdk/8.0.303/Microsoft.Common.CurrentVersion.targets(2165,5): warning : The referenced project '../../../shared/CA.Protocols.SFTP/CA.Protocols.SFTP.csproj' does not exist.                                                
[/tmp/source/Cwoc/Cwoc.csproj]                                                                                                                                                                                              
... docker run: /tmp/source/Cwoc/Di.cs(4,7): error CS0246: The type or namespace name 'CA' could not be found (are you missing a using directive or an assembly reference?)                                                               
[/tmp/source/Cwoc/Cwoc.csproj]                                                                                                                                                                                              
... docker run: /tmp/source/Cwoc/Di.cs(5,7): error CS0246: The type or namespace name 'CA' could not be found (are you missing a using directive or an assembly reference?)                                                               
[/tmp/source/Cwoc/Cwoc.csproj]                                                                                                                                                                                              
... docker run: /tmp/source/Cwoc/Handlers/OrderRxHandler.cs(4,7): error CS0246: The type or namespace name 'CA' could not be found (are you missing a using directive or an assembly reference?)                                          
[/tmp/source/Cwoc/Cwoc.csproj]                                                                                                                                                                                              
... docker run: /tmp/source/Cwoc/Handlers/OrderRxHandler.cs(5,7): error CS0246: The type or namespace name 'CA' could not be found (are you missing a using directive or an assembly reference?)                                          
[/tmp/source/Cwoc/Cwoc.csproj]                                                                                                                                                                                              
... docker run: /tmp/source/Cwoc/Handlers/OrderRxHandler.cs(6,7): error CS0246: The type or namespace name 'CA' could not be found (are you missing a using directive or an assembly reference?)                                          
[/tmp/source/Cwoc/Cwoc.csproj]                                                                                                                                                                                              
... docker run: /tmp/source/Cwoc/Handlers/OrderTxHandler.cs(3,7): error CS0246: The type or namespace name 'CA' could not be found (are you missing a using directive or an assembly reference?)                                          
[/tmp/source/Cwoc/Cwoc.csproj]                                                                                                                                                                                              
...                          
[/tmp/source/Cwoc/Cwoc.csproj]                                                                                                                                                                                              
ERROR: Container build returned 1                                                                                                                                                                                                                                       

Build Failed
Error: DotnetCliPackageBuild
Beau-Gosse-dev commented 1 month ago

Related: https://github.com/aws/aws-extensions-for-dotnet-cli/discussions/332

kyl3t commented 1 month ago

As mentioned by @normj in this discussion - "code-mount-directory" can be set in the aws-lambda-tools-defaults.json to reference a path that the dotnet lambda command eventually uses.

mndeveci commented 1 month ago

Resolving this issue assuming this is already resolved in the other thread above. Please let us know if you have any other questions.

github-actions[bot] commented 1 month ago

⚠️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.