cloudydeno / deno-aws_api

From-scratch Typescript client for accessing AWS APIs
https://deno.land/x/aws_api
59 stars 3 forks source link

Error when making AWS API calls on windows #40

Closed GJZwiers closed 1 year ago

GJZwiers commented 1 year ago

First of all thank you for making this module, it is very nice! I noticed that on windows there is an error when trying to load the AWS credentials. My credentials are located in the default location for the file on windows C:\Users\<MyUser>\.aws\credentials and this is an example of code that errors:

import { ApiFactory } from 'https://deno.land/x/aws_api@v0.7.0/client/mod.ts';
import { CloudFormation } from "https://aws-api.deno.dev/v0.3/services/cloudformation.ts";

const cfn = new ApiFactory({
    region: 'eu-west-3'
}).makeNew(CloudFormation);

const result = await cfn.describeStacks();

console.log(result);

Error:

deno run -A  .\life.ts
error: Uncaught (in promise) Error: Failed to load any possible AWS credentials:
    - ()=>new EnvironmentCredentials('AWS') Error: AWS environment variables not set
    - ()=>new EnvironmentCredentials('AMAZON') Error: AMAZON environment variables not set
    - ()=>new SharedIniFileCredentials() NotFound: The system cannot find the path specified. (os error 3)    
    - ()=>new EcsTaskCredentials() Error: AWS_CONTAINER_CREDENTIALS_RELATIVE_URI not set
    - ()=>new TokenFileWebIdentityCredentials() Error: No WebIdentityToken file path is set
    - ()=>new EC2MetadataCredentials() TypeError: error sending request for url (http://169.254.169.254/latest/api/token): error trying to connect: tcp connect error: A socket operation was attempted to an unreachable network. (os error 10051)
    return Promise.reject(new Error([
                          ^
    at CredentialsProviderChain.getCredentials (https://deno.land/x/aws_api@v0.7.0/client/credentials.ts:44:27)
    at async QueryServiceClient.signingFetcher [as signedFetcher] (https://deno.land/x/aws_api@v0.7.0/client/client.ts:89:29)
    at async QueryServiceClient.performRequest (https://deno.land/x/aws_api@v0.7.0/client/client.ts:179:22)   
    at async CloudFormation.describeStacks (https://aws-api.deno.dev/v0.3/services/cloudformation.ts:606:18)  
    at async file:///C:/Users/GJZwiers/repos/deno_deno/life.ts:8:16

I also use WSL (Ubuntu) with credentials at ~/.aws/credentials and on there it works as normal.

danopia commented 1 year ago

Hi, thanks for the report! This is likely the same exact issue that my /x/kubernetes_client library had on Windows. I can't say I'm surprised, I included a TODO comment: https://github.com/cloudydeno/deno-aws_api/blob/3ce25f2e9fb1f547bad61afdaa4676f60ddce497/lib/client/credentials.ts#L86-L88

Anyway, I've started a fix:

To test the fix, please use this import:

import { ApiFactory } from 'https://raw.githubusercontent.com/cloudydeno/deno-aws_api/4a9d5be8044abdc7d2d50186e9e9c0775d09d9a2/lib/client/mod.ts';
GJZwiers commented 1 year ago

I've just tried it out, it looks like it fixed the issue. Working on both windows and WSL now

danopia commented 1 year ago

Great, thanks for reporting back! :)

I should be able to get a release out sometime this week, depends on what else needs work while I'm in the area

danopia commented 1 year ago

🚀 This fix finally shipped in a tag today: v0.8.0