I'm trying to send an email using AWS SES from a Supabase cloud function. I've set up the AWS env variables, but it still tries to read the config from filesystem, which fails 'cause there's no filesystem in the edge runtime?
The env vars I set are:
AWS_ACCESS_KEY_ID=key
AWS_SECRET_ACCESS_KEY=secret
AWS_REGION=us-east-2
AWS_DEFAULT_REGION=us-east-2
AWS_DEFAULT_PROFILE=default
AWS_SDK_LOAD_CONFIG=
I know some of these vars are redundant but, I'm trying everything at this point.
The error I keep getting is:
runtime has escaped from the event loop unexpectedly: event loop error: TypeError [ERR_INVALID_ARG_TYPE]" argument must be of type string. Received null
at assertPath (ext:deno_node/path/_util.ts:10:11)
at join (ext:deno_node/path/_posix.ts:77:5)
at getCredentialsFilepath (file:///tmp/sb-compile-edge-runtime/node_modules/localhost/@smithy/shared-ini-file-loader/2.3.1/dist-cjs/index.js:75:117)
at loadSharedConfigFiles (file:///tmp/sb-compile-edge-runtime/node_modules/localhost/@smithy/shared-ini-file-loader/2.3.1/dist-cjs/index.js:132:22)
at file:///tmp/sb-compile-edge-runtime/node_modules/localhost/@smithy/node-config-provider/2.2.1/dist-cjs/index.js:51:105
at file:///tmp/sb-compile-edge-runtime/node_modules/localhost/@smithy/property-provider/2.1.1/dist-cjs/index.js:79:33
at eventLoopTick (ext:core/01_core.js:183:11)
at async coalesceProvider (file:///tmp/sb-compile-edge-runtime/node_modules/localhost/@smithy/property-provider/2.1.1/dist-cjs/index.js:106:18)
at async file:///tmp/sb-compile-edge-runtime/node_modules/localhost/@smithy/property-provider/2.1.1/dist-cjs/index.js:117:20
which looks like it forgets that the secrets are in env.
Finally, and maybe most importantly, when I run this:
import {
SESClient,
} from "npm:@aws-sdk/client-ses";
client = new SESClient();
console.log(await client.config.credentialDefaultProvider()());
it actually logs the access key and secret, so, why it still throws the runtime error BAFFLES me
And of course, passing the credentials directly doesn't work either.
OK, it seems when loading the
@aws-sdk/client-sespackage in a "node-like" environment it goes down the path of loading thenode-config-providerwhich then leads to loading theshared-ini-file-loaderThis
shared-ini-file-loaderrelies, as the name suggests, on the functionalities of a file system. The given stacktrace points to this line of codewhere it is trying to determine a home directory, which of course doesn't exist if there is no file-system. You could probably prevent this call to
getHomeDir()here by setting theENV_CREDENTIALS_PATHto some dummy value. This might be enough to bypass that error. But it also may just allow you one further step before failing somewhere else with the next function trying to access the file system. I have no environment where I can reproduce this, so this may or may not work, but it seems worth a try ...