oven-sh / bun

Incredibly fast JavaScript runtime, bundler, test runner, and package manager – all in one
https://bun.sh
Other
74.48k stars 2.78k forks source link

aws-sts does not work after compiling #11593

Closed cromega closed 15 hours ago

cromega commented 5 months ago

What version of Bun is running?

1.1.12+43f0913c3

What platform is your computer?

Linux 6.5.0-35-generic x86_64 unknown

What steps can reproduce the bug?

I'm trying to build a CLI tool which wraps quite a few AWS libraries. I'm running into problems running the tool after compilation.

Here is an example project to reproduce the issue.

package.json:

{
  "name": "aws-getsession-test",
  "module": "index.ts",
  "type": "module",
  "devDependencies": {
    "@types/bun": "latest"
  },
  "peerDependencies": {
    "typescript": "^5.0.0"
  },
  "dependencies": {
    "@aws-sdk/client-sts": "^3.588.0"
  }
}

index.ts:

import { STSClient, GetSessionTokenCommand } from "@aws-sdk/client-sts";

const region = process.env.AWS_REGION
if (!region || region.length == 0) { console.log('Region is required'); process.exit(1) }

const sts = new STSClient({region: region})

const request: GetSessionTokenCommand = new GetSessionTokenCommand({})
const response = await sts.send(request)
console.log(response.Credentials)

What is the expected behavior?

{
  AccessKeyId: "ASIAxxxxxxxxxxxxx",
  SecretAccessKey: "aws-secret-key-xxxxxxxxxxxxxxxxxxxxxx",
  SessionToken: "lengthy aws session token here",
  Expiration: 2024-06-04T22:27:27.000Z,
}

What do you see instead?

root@0cc4cc2b89f3:/app# AWS_REGION=eu-west-2 ./test 
681 | });
682 | 
683 | // node_modules/@smithy/util-endpoints/dist-es/types/EndpointError.js
684 | class EndpointError extends Error {
685 |   constructor(message) {
686 |     super(message);
          ^
EndpointError: Invalid Configuration: Missing Region
      at new EndpointError (/$bunfs/root/test:686:5)
      at evaluateErrorRule (/$bunfs/root/test:1147:11)
      at evaluateRules2 (/$bunfs/root/test:1187:9)
      at resolveEndpoint (/$bunfs/root/test:1229:23)
      at /$bunfs/root/test:8186:23

Additional information

The code works when executed with AWS_PROFILE=eu-west-2 bun run index.ts

The code breaks with the aforementioned error when executed with:

bun build --compile --outfile test index.ts
AWS_PROFILE=eu-west-2 ./test

The version of the @aws-sdk/client-sts package is 3.588.0

NOTE: you need an AWS user and access credentials configured.

PandelisZ commented 5 months ago

oh my gosh this was driving me crazy. It is indeed broken gosh. Im sorry I don't have a fix for you, I removed the SST code to fix it on our end

cromega commented 5 months ago

That's alright, Thanks for looking into it, I'm glad the problem exists and is acknowledged. I will patiently wait for further updates :)

PandelisZ commented 5 months ago

Woke up to this having popped up again but upgrading the AWS SDK helped this time

systemd[1]: Failed with result 'exit-code'.
Jul 01 : 24880 | // ../..[REDACTED]@aws-sdk/client-sso/dist-es/SSOClient.js
Jul 01 : 24881 | class SSOClient extends smithy_client20.Client {
Jul 01 :                                 ^
Jul 01 : TypeError: undefined is not an object (evaluating 'smithy_client20.Client')
Jul 01 :       at /$bunfs/root/server:24881:25
Jul 01 : pam_unix(sudo:session): session closed for user root
Jul 01 : swe.service: Main process exited, code=exited, status=1/FAILURE
❯ pnpm up -i -L                                                                                                                                                                                                                                             
dependencies:
- @aws-sdk/client-batch 3.598.0
+ @aws-sdk/client-batch 3.606.0
- @aws-sdk/client-cloudwatch-logs 3.598.0
+ @aws-sdk/client-cloudwatch-logs 3.606.0
- @aws-sdk/client-sts 3.598.0
+ @aws-sdk/client-sts 3.606.0
cromega commented 15 hours ago

I tried compiling my project with bun again and this time it seems to work fine, not sure what changed but thanks to whoever was responsible :)