Bug: sam build does not work with sso and CodeArtifact NuGet repository
Description:
sam build command fails to build a dotnet6 Lambda application. The output shows a NuGet error with 401 (Unauthorized).
Steps to reproduce:
- Configure a private NuGet CodeArtifact repository in Visual Studio 2022.
- Use an AWS IAM Identity Center profile to provide access to the CodeArtifact repository.
- Login to AWS IAM Identity Center via AWS Toolkit for Visual Studio 2022, or the
aws sso logincommand. - Create a dotnet6 Lambda project.
- Include NuGet packages that are from the private CodeArtifact repository.
- Attempt the run the
sam buildcommand.
Observed result:
Attached here is the full output with the --debug flag set: sam-build-output.log
... publish: MSBuild version 17.5.0+6f08c67f3 for .NET
... publish: Determining projects to restore...
... publish: Retrying 'FindPackagesByIdAsync' for source 'https://epic-river-739313777237.d.codeartifact.us-east-1.amazonaws.com/nuget/epic-river-private/v3/flatcontainer/awssdk.core/index.json'.
... publish: Response status code does not indicate success: 401 (Unauthorized).
... publish: Retrying 'FindPackagesByIdAsync' for source 'https://epic-river-739313777237.d.codeartifact.us-east-1.amazonaws.com/nuget/epic-river-private/v3/flatcontainer/awssdk.s3/index.json'.
... publish: Response status code does not indicate success: 401 (Unauthorized).
... publish: Failed to restore D:\Users\TKing\dev\ProSignOnline\TransactionExportApp\src\ExportTransaction\ExportTransaction.csproj (in 6.27 sec).
... publish: 1 of 2 projects are up-to-date for restore.
Failed to create application package
Build Failed
Expected result:
The build succeeds and I can proceed to sam deploy.
Additional environment details (Ex: Windows, Mac, Amazon Linux etc)
- OS: Windows 10 on Amazon WorkSpace
sam --version: 1.78.0- AWS region: us-east-1
$> sam --info
{
"version": "1.78.0",
"system": {
"python": "3.8.8",
"os": "Windows-10-10.0.14393-SP0"
},
"additional_dependencies": {
"docker_engine": "Not available",
"aws_cdk": "Not available",
"terraform": "Not available"
}
}
The fix for this was to install the CodeArtifact NuGet Credential Provider from scratch. Something wasn't quite right with how the Toolkit's installation of the Credential Provider worked with the CLI. Make sure to follow the instruction that says "To use the credential provider, ensure that any existing AWS CodeArtifact credentials are cleared from your nuget.config file that may have been added manually or by running aws codeartifact login to configure NuGet previously."
⚠️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.