Skip to content

AWS Lambda .NET Core Deployment does not always make use of supplied AWS Credentials #135

@svisagie

Description

@svisagie

We've found that the AWS Lambda .NET Core Deployment task does not always make use of credentials in the supplied AWS Credentials. The credentials contains just an access id and secret access key, no role to assume.

We have a pipeline containing releases to multiple environments hosted in different AWS accounts using different credentials for each one.

The problem shows up in the logs that the connect S3 bucket region cannot be detected due to AccessDenied and then also later down when the the dotnet lambda package-ci process tries to upload the file to S3 it also fails due to an access denied error.

I've had a look through the NetCoreDeployTaskOperations.ts file and the problem seems to be related to what happens around line 40 where the following is found;

const env = process.env;

        // If assume role credentials are in play, make sure the initial generation
        // of temporary credentials has been performed. If no credentials were defined
        // for the task, we assume they are already set in the host environment.
        const credentials = await this.taskParameters.getCredentials();
        if (credentials) {
            env.AWS_ACCESS_KEY_ID = credentials.accessKeyId;
            env.AWS_SECRET_ACCESS_KEY = credentials.secretAccessKey;
            if (credentials.sessionToken) {
                env.AWS_SESSION_TOKEN = credentials.sessionToken;
            }
        }

        const region = await this.taskParameters.getRegion();

the last line is what throws the first error stating:

Warning: Unable to determine region for bucket BUCKETNAME, assuming bucket is in correct region: Access Denied

I think this is due to the fact that the dotnet lambda package-ci tool is not explicitly provided with the credentials supplied in the AWS Credentials setting, but rather relying of environment variables.

I've mostly managed to get around the issue by adding an AWS Powerhsell task before this task which has the same credentials and region specified and it just does the default Hello World message. This workaround doesn't always work and the deploy sometimes needs to be run for a second time for the credentials to actually take.

The issue is not permissions since this same AWS Credentials is used in several other places without any issue to push packages to S3 for CodeDeploy.

Metadata

Metadata

Assignees

No one assigned

    Labels

    blockedbugWe can reproduce the issue and confirmed it is a bug.

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions