AWS SDK in Tail Worker?

Is it possible to use aws sdks in workers? I see Cloudflare have an example repo https://github.com/cloudflare/workers-aws-template/blob/master/index.js However, when I try to deploy my worker it fails due to the SDK requiring Node APIs under the hood (see screenshot). My worker has Node compatibility specified in the wrangler file i.e. compatibility_flags = ["nodejs_compat"] However, I also note from the Cloudflare docs (https://developers.cloudflare.com/workers/runtime-apis/nodejs/) that the fs module is not supported. Additionally, the sdk does not import the modules as suggested by the docs e.g. import { Buffer } from 'node:buffer'; (which I obviously can not change). Has anyone managed to get this to work? Or is it a known limitation? My thinking was since they provide an example then it must be possible.
GitHub
workers-aws-template/index.js at master · cloudflare/workers-aws-te...
Cloudflare Workers template for accessing AWS services such as DynamoDB and SQS - cloudflare/workers-aws-template
Cloudflare Docs
Node.js compatibility · Cloudflare Workers docs
Implemented Node.js runtime APIs and enablement instructions for your Worker project.
No description
6 Replies
ItsWendell
ItsWendell5mo ago
What SDK are you specifically trying to use? You can try the compat flag experimental:nodejs_compat_v2 which is experimental, and not recommended to be used in production, but worth a shot.
Richard
RichardOP5mo ago
Trying to use @aws-sdk/client-s3 and @aws-sdk/client-sns. Gave the above a shot - could not get it to work. What I did change was removed compatibility_flags = ["nodejs_compat"] and used node_compat = true. This seems to polyfill most of the APIs except for http2 and v8 (will attach a pic). So currently looking for a solution to somehow polfyill these two aswell (if it's possible).
Richard
RichardOP5mo ago
No description
ItsWendell
ItsWendell5mo ago
This will probably not work at all, http and v8 can't really be polyfilled. There are alternatives implementations though to talk to AWS, for example: https://github.com/mhart/aws4fetch
GitHub
GitHub - mhart/aws4fetch: A compact AWS client and signing utility ...
A compact AWS client and signing utility for modern JS environments - mhart/aws4fetch
ItsWendell
ItsWendell5mo ago
GitHub
cf-s3-uploader/src/router.ts at master · yusukebe/cf-s3-uploader
Cloudflare Worker for uploading images to Amazon S3 - yusukebe/cf-s3-uploader
Richard
RichardOP5mo ago
Thanks for the info! Yeah came across aws4fetch which looks interesting. Was hoping to find some examples with SNS which I havn't been able to find (yet). I came across this example of someone using SDKs in workers (although could not confirm if it actually works) which gives me hope that it is in fact possible somehow https://github.com/winstxnhdw/mail-worker
GitHub
GitHub - winstxnhdw/mail-worker: A mail worker built with Cloudflar...
A mail worker built with Cloudflare Workers and AWS SES. - winstxnhdw/mail-worker
Want results from more Discord servers?
Add your server