我正在尝试在AWS API网关上调用我的REST API方法,但我得到以下错误消息:API MyAPI does not exist
这就是我如何从我的代码中配置AWS Amplify,并从我的App.tsx中调用它,类似于https://docs.amplify.aws/lib/restapi/getting-started/q/platform/js/#configure-your-application:
上记录的内容import { Amplify } from 'aws-amplify';
export const AwsConfig = () => {
Amplify.configure({
Auth: {
region: 'xxxxxxxx',
userPoolId: 'xxxxxxxx',
userPoolWebClientId: 'xxxxxxxx',
mandatorySignIn: true,
},
API: {
name: "MyAPI",
endpoint: "https://xxxxxxx.execute-api.xxxxxxx.amazonaws.com/test",
region: 'xxxxxxxx',
}
});
}
然后,根据Amplify CLI自动生成的。/aws-exports文件和我的REST API调用工作正常,我尝试使用以下命令:
import { Amplify } from 'aws-amplify';
export const AwsConfig = () => {
Amplify.configure({
aws_project_region: 'xxxxxxxx',
aws_cloud_logic_custom: [
{
name: 'MyAPI',
endpoint: 'https://xxxxxxxx.execute-api.xxxxxxxx.amazonaws.com/test',
region: 'xxxxxxxx'
}
],
Auth: {
region: 'xxxxxxxx',
userPoolId: 'xxxxxxxx',
userPoolWebClientId: 'xxxxxxxx',
mandatorySignIn: true,
},
});
}
为什么会这样?第一种方法有什么问题?
我认为在第一种方法中,您需要将API指定为具有端点列表(其中包含单个API)。区域值也可能导致它不工作(这似乎只有在使用区域端点/指向lambda(与API Gateway相反)时才需要)。我想试试以下方法:
API: {
endpoints: [
{
name: "MyAPI",
endpoint: "https://xxxxxxx.executeapi.xxxxxxx.amazonaws.com/test",
}
]
}