I want to define both a Lambda function and a DynamoDB table in an Amplify application. I wrote the following code in data/resource.ts, but when running the ampx sandbox command, an error is displayed. Is there something wrong with my approach?
data/resource.ts
import { type ClientSchema, a, defineData } from '@aws-amplify/backend';
import { getRss } from '../functions/get-rss/resource';
const schema = a.schema({
getRss: a
.query()
.arguments({
name: a.string(),
})
.returns(a.string())
.authorization((allow) => [allow.guest()])
.handler(a.handler.function(getRss)),
Rss: a
.model({
title: a.string(),
link: a.string(),
ai_summary: a.string(),
is_read: a.boolean(),
is_deleted: a.boolean(),
published_at: a.string(),
updated_at: a.string(),
fetched_at: a.string(),
})
.authorization((allow) => [allow.authenticated()]),
});
export type Schema = ClientSchema<typeof schema>;
export const data = defineData({
schema,
authorizationModes: {
defaultAuthorizationMode: 'iam',
},
});
Error:
Failed to instantiate data construct
Caused By: Object type extension 'Query' cannot redeclare field getRss
Resolution: See the underlying error message for more details.
I saw that this error is resolved when I removed Rss schema in a.schema({}).