我使用 gen2 创建了一个 lambda 函数,如下所示:
amplify/functions/send-link-file/resource.ts 文件:
import { defineFunction } from '@aws-amplify/backend';
export const sendReportEmail = defineFunction({
name: 'send-report-email',
entry: './handler.ts',
timeoutSeconds: 180
});
hander.ts 文件:
import {SendRawEmailCommand, SESClient, } from '@aws-sdk/client-ses';
import { CreateForm1 } from './pdf';
const sesClient = new SESClient({region: 'ap-south-1'});
export const handler = async (event: any, context: any) =\> {
\------ rest of the logic...
return 'success';
}
backend.ts 文件:
import { defineBackend } from '@aws-amplify/backend';
import {Effect, PolicyStatement} from "aws-cdk-lib/aws-iam"
import { auth } from './auth/resource.js';
import { data } from './data/resource.js';
import { sendLinkEmail } from './functions/send-link-email/resource';
import { sendReportEmail } from './functions/send-report-email/resource';
const backend = defineBackend({
auth,
data,
sendLinkEmail,
sendReportEmail
});
沙盒中一切运行良好。但是在部署时,我收到以下错误:
2024-09-22T19:41:30.538Z \[INFO\]: # Executing command: npx ampx pipeline-deploy --branch $AWS_BRANCH --app-id $AWS_APP_ID --debug
54 2024-09-22T19:41:55.774Z \[INFO\]: \[DEBUG\] 2024-09-22T19:41:55.773Z: npm
55 2024-09-22T19:41:55.780Z \[INFO\]: \[DEBUG\] 2024-09-22T19:41:55.774Z: WARN exec The following package was not found and will be installed: [email protected]
56 2024-09-22T19:42:00.121Z \[INFO\]: \[DEBUG\] 2024-09-22T19:42:00.120Z: /codebuild/output/src4216656133/src/medical-amplify/node_modules/@aws-amplify/backend-function/src/factory.ts:35
57 CallerDirectoryExtractor,
^
59 SyntaxError: The requested module '@aws-amplify/platform-core' does not provide an export named 'CallerDirectoryExtractor'
60 at ModuleJob.\_instantiate (node:internal/modules/esm/module_job:124:21)
61 at async ModuleJob.run (node:internal/modules/esm/module_job:190:5)
如何解决这个问题?
我正在尝试使用 aws amplify gen2 函数。 `
这一定是版本不同的问题, 确保所有 Amplify 软件包(尤其是
@aws-amplify/backend-function
和 @aws-amplify/platform-core
)兼容,方法是将它们更新到 package.json
中的相同版本,然后重新部署
npm install @aws-amplify/backend-function @aws-amplify/platform-core@latest --save
有时,陈旧或损坏的软件包安装可能会导致问题。您可以清除
npm cache
并重新安装依赖项:
npm cache clean --force
rm -rf node_modules
npm install