question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

Calling AddSystemsManager using a profile that assumes role throws exception

See original GitHub issue

Description

When using a profile that assumes a role (no MFA involved), calling the AddSystemsManager extension method from within Visual Studio 2019 using the Mock Lambda Test Tool throws an exception:

System.InvalidOperationException: ‘Assembly AWSSDK.SecurityToken could not be found or loaded. This assembly must be available at runtime to use Amazon.Runtime.AssumeRoleAWSCredentials.’

I’d expect that the correct role is assumed and the relevant parameters are fetched when calling the AddSystemsManager extension method. I think this is a bug as I cant see anything wrong on my end.

There’s a similar issue open, #155, however the comments on it suggest that is specifically an issue because of MFA. The issue I’m facing has nothing to do with MFA (or at least, neither my account nor my credentials profile uses any MFA).

Reproduction Steps

Credentials file

[default]
aws_access_key_id=my_key
aws_secret_access_key=my_secret
region=eu-west-1

[profile-assumes-role]
role_arn = arn:aws:iam::my_account:role/my_role
source_profile = default
region=eu-west-1

appsettings.Development.json file

{
  "AWS": {
    "Region": "eu-west-1",
    "Profile": "profile-assumes-role"
  }
}

Code

public class Function
{
    public void FunctionHandler()
    {
        var config = new ConfigurationBuilder()
            .SetBasePath(Directory.GetCurrentDirectory())
            .AddJsonFile("appsettings.Development.json")
            .AddSystemsManager("/path-to-parameters/") // throws ex after brief wait
            .Build();
    }
}

Project Dependencies

<PackageReference Include="Amazon.Extensions.Configuration.SystemsManager" Version="2.1.0" />
<PackageReference Include="Amazon.Lambda.Core" Version="1.2.0" />
<PackageReference Include="Amazon.Lambda.Serialization.SystemTextJson" Version="2.1.0" />
<PackageReference Include="AWSSDK.Extensions.NETCore.Setup" Version="3.7.0.1" />
<PackageReference Include="Microsoft.Extensions.Configuration" Version="5.0.0" />
<PackageReference Include="Microsoft.Extensions.Configuration.FileExtensions" Version="5.0.0" />
<PackageReference Include="Microsoft.Extensions.Configuration.Json" Version="5.0.0" />

Logs

Not sure how to get logs. The link mentioned in the bug template is specifically for .Net Framework. It points me to another page for .Net Core which has no information on logging.

Environment

  • Build Version: See dependency versions above
  • OS Info: Windows 10
  • Build Environment: Visual Studio 2019
  • Targeted .NET Platform: .Net Core 3.1

Resolution

  • 👋 I can/would-like-to implement a fix for this problem myself

This comment on issue #155 mention that AWSSDK.SecurityToken assembly needs to be added to the list of dependencies, however there would be further issues with MFA because the Lambda tooling doesnt support a prompt for MFA token. Perhaps this assembly should be added as a dependency regardless of the missing MFA prompt, which may fix the issue I’m seeing?


This is a 🐛 bug-report

Issue Analytics

  • State:closed
  • Created 2 years ago
  • Comments:5 (3 by maintainers)

github_iconTop GitHub Comments

1reaction
chrisoverzerocommented, Aug 10, 2021

I really didnt want to introduce this dependency for the sake of testing the code locally, when it’s not required while the code is running within the AWS environment.

Oh, no worries there. Development dependencies (PrivateAssets="All") don’t get deployed.

0reactions
github-actions[bot]commented, Aug 21, 2021

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

Read more comments on GitHub >

github_iconTop Results From Across the Web

Assume a role with AWS STS using an AWS SDK
The following code examples show how to assume a role with AWS STS. Action examples are code excerpts from larger programs and must...
Read more >
assume-role — AWS CLI 1.29.31 Command Reference
Description ¶. Returns a set of temporary security credentials that you can use to access Amazon Web Services resources. These temporary credentials consist...
Read more >
Troubleshoot IAM assume role errors "AccessDenied" or " ...
I tried to assume a cross-account AWS Identity and Access Management (IAM) role. However, I received an error similar to the following: "An...
Read more >
How enable access to AWS STS AssumeRole
I am getting an error when calling to assume role method of STS. It says that the user is not authorized to perform...
Read more >
How to assume a role with AWS Security Token Service (STS)
We will later use this user and assume a role called my-test- role which ... trying to use expired credentials will throw an...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found