Open rhaenni opened 11 months ago
Most likely related to or even a dupe of https://github.com/unjs/unenv/issues/86 -> https://github.com/unjs/unenv/issues/92
I think cloudflare doesn't support aws-sdk
. Try using aws4fetch instead.
@cosbgn cloudflare supports aws-sdk
, I can send emails in a simple worker using script below.
But I can't do it in the Nuxt / Nitro event handler, cloudflare throws an error.
@manniL issues you mentioned were closed in unjs/unenv v1.9.0... Any idea why SESClient still throws an error:
Cannot convert object to primitive value
import { SESClient, SendEmailCommand } from '@aws-sdk/client-ses'
export default eventHandler(async () => {
const message = {
Subject: { Data: 'subject' },
Body: { Html: { Data: 'body' } },
}
const mail = new SendEmailCommand({
Source: 'test@test.com',
ReturnPath: 'test@test.com',
Destination: { ToAddresses: ['test@test.com'] },
Message: message,
})
const credentials = {
accessKeyId: '***',
secretAccessKey: '***',
}
const client = new SESClient({
region: 'eu-central-1',
credentials,
});
const send_mail = await client.send(mail).catch(console.error)
return send_mail ? { message: 'Email sent' } : { message: 'Error' }
})
Cannot convert object to primitive value
at e.defaultUserAgent (chunks/index.mjs:1:394301)
at gp.getRuntimeConfig (chunks/index.mjs:1:487967)
at new SESClient (chunks/index.mjs:1:489918)
at chunks/test.mjs:1:347
at chunks/nitro/cloudflare-pages.mjs:1:62477
at async Object.handler (chunks/nitro/cloudflare-pages.mjs:1:62913)
at async chunks/nitro/cloudflare-pages.mjs:1:65282
at async chunks/nitro/cloudflare-pages.mjs:1:104325
@cosbgn cloudflare supports
aws-sdk
, I can send emails in a simple worker using script below.But I can't do it in the Nuxt / Nitro event handler, cloudflare throws an error.
Agree, there's a working example from Cloudflare here.
Most likely related to or even a dupe of unjs/unenv#86 -> unjs/unenv#92
I don't think it's the case since I'm still having this issue.
@leogargioni do you mind making a recent repro? What is latest issue/error you get?
@pi0 sure, thanks for looking into it.
I've created this repo with api examples:
For /api/test1, the log in Cloudflare is:
"[nuxt] [request error] [unhandled] [500]", "Cannot convert object to primitive value\n at defaultUserAgent (chunks//index.mjs:1:314339) \n at Id.getRuntimeConfig (chunks//index.mjs:1:519815) \n at new DynamoDBClient (chunks//index.mjs:1:521815) \n at chunks//ddbClient.mjs:1:206"
Please note that all tests work in dev (npm run dev), but when trying to preview the test1 and test2 also don't work, but locally (with wrangler) the error is "TypeError [ERR_INVALID_FILE_URL_PATH]: File URL path must be absolute" for both endpoints.
To test, you'll need to have a table called "Example" in DynamoDB, I've deployed the local version of DynamoDB to test it locally in development
environment. To create the "Example" table in local DynamoDB run the following command:
aws dynamodb create-table --table-name Example --attribute-definitions AttributeName=PK,AttributeType=S --key-schema AttributeName=PK,KeyType=HASH --provisioned-throughput ReadCapacityUnits=5,WriteCapacityUnits=5 --table-class STANDARD --region=sa-east-1 --endpoint-url http://localhost:8000/
Lastly, FYI, I've followed this guide to create the Nuxt app and deploy in Cloudflare.
Please let me know if you need more info. Thanks.
Environment
Nuxt 3.8.0 with Nitro 2.7.2 vite v4.5.0
Reproduction
https://codesandbox.io/p/github/unjs/nitro/csb-z43zd7/draft/tender-wu
Describe the bug
Can not use AWS-SDK with cloudflare-pages/cloudflare-module Nitro Preset and using wrangler to deploy to Cloudflare, always getting errors from AWS-SDK.
I found a somewhat related issue but don't understand how to workaround: https://github.com/cloudflare/workers-sdk/issues/2081
Additional context
No response
Logs
No response