aws-sam-cli icon indicating copy to clipboard operation
aws-sam-cli copied to clipboard

Bug: sam build does not work with sso and CodeArtifact NuGet repository

Open tking2096 opened this issue 3 years ago • 2 comments

Description:

sam build command fails to build a dotnet6 Lambda application. The output shows a NuGet error with 401 (Unauthorized).

Steps to reproduce:

  1. Configure a private NuGet CodeArtifact repository in Visual Studio 2022.
  2. Use an AWS IAM Identity Center profile to provide access to the CodeArtifact repository.
  3. Login to AWS IAM Identity Center via AWS Toolkit for Visual Studio 2022, or the aws sso login command.
  4. Create a dotnet6 Lambda project.
  5. Include NuGet packages that are from the private CodeArtifact repository.
  6. Attempt the run the sam build command.

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)

  1. OS: Windows 10 on Amazon WorkSpace
  2. sam --version: 1.78.0
  3. 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"
  }
}

tking2096 avatar Apr 11 '23 17:04 tking2096

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."

Installing the CodeArtifact NuGet Credential Provider

tking2096 avatar Apr 11 '23 17:04 tking2096

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

github-actions[bot] avatar Apr 11 '23 17:04 github-actions[bot]