要解决AWS AppSync无法通过VTL解析器访问Aurora Serverless Postgres集群的问题,可以按照以下步骤进行操作:
确保AWS AppSync API已正确配置,并且与Aurora Serverless数据库集群在同一AWS区域中。
在AWS AppSync控制台中,打开您的API,并导航到“数据源”选项卡。
选择现有的数据源或创建新的数据源,然后选择“Amazon RDS”作为数据源类型。
在“Amazon RDS”数据源配置页面上,选择“Aurora Serverless”作为数据库类型。
输入Aurora Serverless数据库集群的终端节点(Endpoint)和数据库名称。
将数据库访问角色(IAM role)配置为具有足够权限以访问您的Aurora Serverless数据库集群。
在AWS AppSync的模式中,定义适当的查询、变更和订阅操作,并使用VTL模板编写数据解析逻辑。
以下是一个示例VTL模板,用于查询Aurora Serverless数据库集群中的数据:
type Query {
getUsers: [User]
}
type User {
id: ID!
name: String!
email: String!
}
dataSource(name: "AuroraServerlessDB") {
type: "AMAZON_RDS"
description: "Aurora Serverless Database"
serviceRoleArn: "arn:aws:iam::123456789012:role/AuroraServerlessDBRole"
rdsHttpEndpointConfig: {
awsRegion: "us-west-2"
endpoint: "database-cluster-endpoint"
databaseName: "mydatabase"
}
}
schema {
query: Query
}
请根据您的实际情况修改上述示例代码中的参数,包括数据库终端节点、数据库名称和IAM角色ARN。
完成上述步骤后,您应该能够通过AWS AppSync的VTL解析器访问Aurora Serverless Postgres集群。