要解决“AWS AppSync增量表的功能没有正常工作”的问题,可以尝试以下步骤:
type MyDataSource {
type: AWS_LAMBDA | AMAZON_DYNAMODB | AMAZON_ELASTICSEARCH | RELATIONAL_DATABASE,
...
deltaSyncConfig: DeltaSyncConfig
}
type DeltaSyncConfig {
baseTableTTL: Int
deltaSyncTableName: String
deltaSyncTableTTL: Int
...
}
const AWS = require('aws-sdk');
const dynamoDB = new AWS.DynamoDB();
const params = {
TableName: 'deltaSyncTableName',
KeySchema: [
{ AttributeName: 'id', KeyType: 'HASH' }, // id为主键
],
AttributeDefinitions: [
{ AttributeName: 'id', AttributeType: 'S' }, // id为字符串类型
],
ProvisionedThroughput: {
ReadCapacityUnits: 5,
WriteCapacityUnits: 5
},
GlobalSecondaryIndexes: [ // 如果有定义索引,则添加相应的配置
{
IndexName: 'indexName',
KeySchema: [
{ AttributeName: 'attributeName', KeyType: 'HASH' },
],
Projection: {
ProjectionType: 'ALL',
},
ProvisionedThroughput: {
ReadCapacityUnits: 5,
WriteCapacityUnits: 5,
},
}
]
};
dynamoDB.createTable(params, (err, data) => {
if (err) {
console.error('Error creating delta sync table: ', err);
} else {
console.log('Delta sync table created successfully.');
}
});
type Subscription {
...
mySubscription: MyDataSourceSubscription
}
type MyDataSourceSubscription {
...
onDeltaSyncTable: MyDataSource @aws_subscribe(mutations: ["createMyDataSource", "updateMyDataSource", "deleteMyDataSource"])
}
const AWS = require('aws-sdk');
const dynamoDBStreams = new AWS.DynamoDBStreams();
exports.handler = async (event) => {
const records = event.Records;
for (const record of records) {
if (record.eventName === 'INSERT') {
// 处理INSERT事件
} else if (record.eventName === 'MODIFY') {
// 处理MODIFY事件
} else if (record.eventName === 'REMOVE') {
// 处理REMOVE事件
}
}
return 'Successfully processed records.';
};
如果以上步骤仍然无法解决问题,建议参阅AWS AppSync和相关服务的官方文档,查找更多有关增量表功能配置和使用的信息,并在AWS开发者论坛或AWS支持中心提问,以获取更详细的帮助。