Search code examples
amazon-web-services.net-assemblyaws-powershell

Unable to authenticate when invoking AWS cmdlets with SSO profile in visual studio code


I'm using visual studio code with the AWS cli version 2.9.13, I've got an SSO profile configured which I use to authenticate to the AWS service using device code authentication - I can then use this profile to connect to our AWS code commit repository however when trying to invoke any of the AWS PowerShell cmdlets I'm getting the below error returned;

 Assembly AWSSDK.SSOOIDC could not be found or loaded. This assembly must be available at runtime to use Amazon.Runtime.Internal.SSOServiceClientHelpers, AWSSDK.Core, Version=3.3.0.0, Culture=neutral, PublicKeyToken=885c28607f98e604.

This error is returned each time I use the profile parameter as shown below

-ProfileName MySSOProfile

What i've done so far;

  • Re installed the AWS modules i'm trying to use and installed the latest version
  • Updated all packages on my WSL to the latest versions
  • Installed the AWS Toolkit extension for visual studio, now on version 1.60.0
  • Installed AWSSDK.Core --version 3.7.103.13

What do I need to do to resolve this error and so that I can use my authenticated AWS profile to invoke the AWS cmdlets?


Solution

  • Using SSO credentials from either the .NET SDK or AWS Tools for PowerShell requires a dependency on the SDK's own SSO and SSOOIDC mdoules.

    Install-Module AWS.Tools.Installer
    Install-AWSToolsModule S3, SSO, SSOOIDC
    
    # Since we're not invoking a cmdlet from these modules directly, 
    # we must import them explicitly
    Import-Module AWS.Tools.SSO
    Import-Module AWS.Tools.SSOOIDC
    
    # AWS Tools for PowerShell doesn't support the SSO login flow yet, so login with the CLI
    aws sso login --profile MySSOProfile
    
    # Now we can invoke cmdlets using the SSO profile
    Get-S3Bucket -ProfileName MySSOProfile
    

    See also Update AWS CLI credentials from AWS IAM Identity Center by using PowerShell