awslabs / amazon-emr-vscode-toolkit

A VS Code Extension to make it easier to manage and develop Spark jobs on EMR
https://marketplace.visualstudio.com/items?itemName=AmazonEMR.emr-tools
Apache License 2.0
29 stars 3 forks source link

Error fetching AWS credentials when using remote ssh + dev container vscode extensions #27

Open jlafaye opened 1 year ago

jlafaye commented 1 year ago

Hello,

Trying to use the toolkit with the following setup

What works

What does not work

Error fetching EMR Serverless applications!CredentialsProviderError: Could not load credentials from any providers

It would be great if you could provide guidance on how to troubleshoot this. I would be happy to provide more details if needed. The toolkit is a great addition to VSCode and I'm sure it can ease the developer's lives.

dacort commented 1 year ago

Hi @jlafaye - Thanks for opening the issue and apologies that things aren't working out for you. Just to clarify - you're SSH'ed into an EC2 instance and then also have a devcontainer/Docker environment running on that instance?

How does your devcontainer authenticate to AWS? In other words, if the IAM role is attached to the EC2 instance itself, how does the devcontainer make use of that role?

I haven't tried running this in a remote environment so bear with me. A couple things to try:

  1. If you choose EMR: Select AWS Profile from the command palette, are you provided with a list of profiles? And if so, are they from your local computer or the dev environment?
  2. Make sure you've selected the proper region as well with the EMR: Select AWS Region command.

If neither of those provide insight, I'll both try to set up a remote environment and add better error logging. At the moment, if you click on the OUTPUT tab in VS Code, there is an "Amazon EMR" section, but the current logs are just status logs.

jlafaye commented 1 year ago

Hi @dacort - Thank you for taking the time to read my message.

My devcontainer authenticates to AWS through instance Metadata inherited from the instance the container is running on. I have set AWS_EC2_METADATA_DISABLED to false in devcontainer.json.

  1. EMR Select AWS Profile does not list any profile
  2. Changing to the correct region (eu-west-1 in my case) does not change anything.

Sorry not being able to provide more info.

dacort commented 1 year ago

Just leaving some debugging notes:

Next, need to try setting up ssh + devcontainer.

For some reason looks like AwsCredentialIdentityProvider in aws_context.ts isn't finding the instance credentials.

The code I used to debug. ```javascript import { GlueClient, GetDatabasesCommand } from "@aws-sdk/client-glue"; import { fromInstanceMetadata } from '@aws-sdk/credential-providers'; console.log('----------------------------------') const credentials = await fromInstanceMetadata({ timeout: 1000, maxRetries: 0, })(); console.log(credentials); console.log('----------------------------------') const glue = new GlueClient({ region: 'us-west-2' }); const result = await glue.send(new GetDatabasesCommand({})); console.log(result.DatabaseList ?? []); ```
dacort commented 1 year ago

Think I figured this out! 😮‍💨

Can you try removing AWS_EC2_METADATA_DISABLED entirely from the containerEnv section of your devcontainer.json file?

When the SDK tries to retrieve credentials from IMDS, it checks for that environment variable, but uses the following code:

if (process.env[ENV_IMDS_DISABLED])

Unfortunately, environment variables come in as strings so even if we set it to false or 0, it evaluates to true.

Leaving this issue open as I'd like to add IMDS as an auth option when creating the container.