Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

DefaultCredentialsProvider is not working for ECS instances #135

Closed
MatteCarra opened this issue Aug 30, 2017 · 8 comments
Closed

DefaultCredentialsProvider is not working for ECS instances #135

MatteCarra opened this issue Aug 30, 2017 · 8 comments

Comments

@MatteCarra
Copy link
Contributor

I was testing a simple program which invokes a lambda.
The program is running nomrmally on my pc with aws credentials setup with aws configure,
but when I deploy it to ecs with the right role it doesn't work and this exception is thrown: https://pastebin.com/P23q2By1.

My code:

val region = "eu-west-1"
val credentialsV2 = DefaultCredentialsProvider.builder().build()
val lambda: LambdaAsyncClient = LambdaAsyncClient.builder().credentialsProvider(credentialsV2).region(Region.of(region)).build()
lambda.invoke(
  InvokeRequest.builder()
    .functionName(myLambda)
      .payload(ByteBuffer.wrap(myBody.toString().getBytes("UTF-8")))
    .build()
).toScala
@jonmcewen
Copy link

I see the same with DynamoDB. Credentials load from file, but not from EC2 instance profile

@MatteCarra MatteCarra changed the title DefaultCredentialsProvider is not working as expected DefaultCredentialsProvider is not working for EC2 instance profile Sep 8, 2017
@eliaslevy
Copy link

Ditt for S3. Confirmed the instance profile works just fine by using the AWS CLI tools.

@frankbregulla1111
Copy link

I think the problem is that the ElasticContainerCredentialsProvider checks whether environment variable AWS_CONTAINER_CREDENTIALS_PATH is present whereas it is called AWS_CONTAINER_CREDENTIALS_RELATIVE_URI in the container on ECS.
(ElasticContainerCredentialsProvider.java:89)

@MatteCarra MatteCarra changed the title DefaultCredentialsProvider is not working for EC2 instance profile DefaultCredentialsProvider is not working for ECS instances Sep 15, 2017
@talton-rmn
Copy link

talton-rmn commented Sep 15, 2017

Edit: Looks like my comment is related to issue #120

I'm running into a similar problem. I added some debug code that would try to get the credentials from each provider individually, and compare them to the results of the DefaultCredentialProvider.

17:54:47 a.ELBWatcher - Env Creds: Failure(software.amazon.awssdk.SdkClientException: Unable to load credentials from system settings. Access key must be specified either via environment variable (AWS_ACCESS_KEY_ID) or system property (aws.accessKeyId).)

17:54:47 a.ELBWatcher - System Creds: Failure(software.amazon.awssdk.SdkClientException: Unable to load credentials from system settings. Access key must be specified either via environment variable (AWS_ACCESS_KEY_ID) or system property (aws.accessKeyId).)

17:54:47 a.ELBWatcher - Profile Creds: Success(null)

17:54:47 a.ELBWatcher - Container Creds: Failure(software.amazon.awssdk.SdkClientException: Credentials cannot be loaded from ECS because the ECS credentials environment variable (AWS_CONTAINER_SERVICE_ENDPOINT) and system property (aws.containerServiceEndpoint) are not set or cannot be accessed due to the security manager.)

17:54:47 a.ELBWatcher - Instance Creds: Success(AwsSessionCredentials(<scrubbed>))

17:54:47 a.ELBWatcher - DefaultCredProvider creds: null

It looks like the problem is that software.amazon.awssdk.auth.ProfileCredentialsProvider is returning null instead of throwing an error. AwsCredentialsProviderChain relies on the provider throwing an error, and doesn't check for null values:

    for (AwsCredentialsProvider provider : credentialsProviders) {
        try {
            AwsCredentials credentials = provider.getCredentials();

            log.debug("Loading credentials from {}", provider.toString());

            lastUsedProvider = provider;
            return credentials;
        } catch (RuntimeException e) {
            // Ignore any exceptions and move onto the next provider
            log.debug("Unable to load credentials from {}:{}", provider.toString(), e.getMessage(), e);
        }
    }

@eliaslevy
Copy link

Might be fixed in master by 62f2d8e. Did you try master?

@talton-rmn
Copy link

It looks like -preview-2 is still the latest version available from maven ( https://mvnrepository.com/artifact/software.amazon.awssdk/ec2 ).

Any suggestions on how to use the master branch as a dependency in another project?

@eliaslevy
Copy link

You'd have to build a jar from master yourself and drop it on your project's unmanaged dependencies directory.

@MatteCarra
Copy link
Contributor Author

@eliaslevy I don't think so, but I think @ffriedrich is right.

MatteCarra added a commit to MatteCarra/aws-sdk-java-v2 that referenced this issue Sep 18, 2017
shorea pushed a commit that referenced this issue Sep 18, 2017
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

5 participants