sst / ion

SST v3
https://sst.dev
MIT License
1.88k stars 221 forks source link

"Region is missing" error when adding S3 bucket to framework #494

Closed debashisbiswas closed 3 months ago

debashisbiswas commented 4 months ago

I encountered this error when trying to create a fresh project and adding an S3 bucket following the docs at https://ion.sst.dev/docs/start/aws/svelte/. I was able to reproduce the same issue in the included template as well. Here are the reproduction steps:

Error: Region is missing
    at default (/home/almia/dev/ion/examples/aws-svelte-kit/node_modules/@smithy/config-resolver/dist-cjs/index.js:117:11)
    at /home/almia/dev/ion/examples/aws-svelte-kit/node_modules/@smithy/node-config-provider/dist-cjs/index.js:90:104
    at /home/almia/dev/ion/examples/aws-svelte-kit/node_modules/@smithy/property-provider/dist-cjs/index.js:97:33
    at async coalesceProvider (/home/almia/dev/ion/examples/aws-svelte-kit/node_modules/@smithy/property-provider/dist-cjs/index.js:124:18)
    at async /home/almia/dev/ion/examples/aws-svelte-kit/node_modules/@smithy/property-provider/dist-cjs/index.js:135:20
    at async useFipsEndpoint (/home/almia/dev/ion/examples/aws-svelte-kit/node_modules/@smithy/config-resolver/dist-cjs/index.js:146:68)
    at async resolveParams (/home/almia/dev/ion/examples/aws-svelte-kit/node_modules/@smithy/middleware-endpoint/dist-cjs/index.js:144:32)
    at async getEndpointFromInstructions (/home/almia/dev/ion/examples/aws-svelte-kit/node_modules/@smithy/middleware-endpoint/dist-cjs/index.js:123:26)
    at async Module.getSignedUrl (/home/almia/dev/ion/examples/aws-svelte-kit/node_modules/@aws-sdk/s3-request-presigner/dist-cjs/index.js:101:24)
    at async load (/home/almia/dev/ion/examples/aws-svelte-kit/src/routes/+page.server.ts:11:14)

I observed this issue in the Astro example as well. I've tried setting the AWS_REGION environment variable to us-east-1 before running, but this did not solve the issue.

The error is on this line:

const url = await getSignedUrl(new S3Client({}), command);

and a fix is to the specify the region directly...

const url = await getSignedUrl(new S3Client({ region: 'us-east-1' }), command);

...however, because the documentation does not do this, this does not seem to be the intended approach.

jayair commented 3 months ago

I wonder if your credentials don't have a default region. You check that.

Also you could try setting it explicitly in your sst config: https://ion.sst.dev/docs/reference/config/#home

Ideally you shouldn't have to set it in the AWS SDKs like that.

debashisbiswas commented 3 months ago

Thanks. Setting the region in the sst config led to the same issue. However, I didn't have a default region set for the AWS CLI, and specifying one resolved this.