Skip to content

Cannot use dotnet lambda with MFA enabled #240

@madmox

Description

@madmox

Describe the bug

I have MFA enabled and required for my IAM user and assumable IAM role, and the appropriate config/credentials file for AWS CLI. I can successfully use the AWS CLI and the SAM CLI (meaning I am prompted for an MFA code and the commands succeed), but the Amazon.Lambda.Tools CLI commands fail to execute and do not even prompt me for an MFA token.

Expected Behavior

dotnet lambda xxx should prompt for the MFA token and successfully execute.

Current Behavior

dotnet lambda xxx does not prompt for the MFA token and fails with the following error:

Amazon Lambda Tools for .NET Core applications (5.4.5)
Project Home: https://github.com/aws/aws-extensions-for-dotnet-cli, https://github.com/aws/aws-lambda-dotnet

<some error message contextual to the command>: Unable to get IAM security credentials from EC2 Instance Metadata Service.

Reproduction Steps

AWS credentials file:

[default]
aws_access_key_id = <aws_access_key_id>
aws_secret_access_key = <aws_secret_access_key>

AWS config file:

[default]
region = eu-west-3
output = json
role_arn = arn:aws:iam::<accountid>:role/<rolename>
source_profile = default
mfa_serial = arn:aws:iam::<accountid>:mfa/<username>

IAM role permissions:

{
    "Version": "2012-10-17",
    "Statement": [
        {
            "Effect": "Allow",
            "Action": "*",
            "Resource": "*"
        }
    ]
}

IAM role trust relationships:

{
    "Version": "2012-10-17",
    "Statement": [
        {
            "Effect": "Allow",
            "Principal": {
                "AWS": "arn:aws:iam::<accountid>:root"
            },
            "Action": "sts:AssumeRole",
            "Condition": {
                "Bool": {
                    "aws:multifactorAuthPresent": "true"
                }
            }
        }
    ]
}

Failing command:

Any dotnet lambda command involving an API call to AWS, such as:

dotnet lambda invoke-function <redacted>

Targeted .NET platform

.NET 6

CLI extension version

amazon.lambda.tools 5.4.5 dotnet-lambda

Environment details (OS name and version, etc.)

Windows 11

Metadata

Metadata

Assignees

No one assigned

    Labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions