Aurora无服务器Postgresql作为应用程序同步的数据源

Aurora无服务器Postgresql作为应用程序同步的数据源,postgresql,serverless,aws-appsync,aws-aurora-serverless,Postgresql,Serverless,Aws Appsync,Aws Aurora Serverless,我遇到了应用程序同步的问题,其中数据源是关系数据库 所以,我的目标是将Aurora无服务器postgresql集群与app sync作为数据源连接起来,并使其正常工作 我执行的步骤(全部通过无服务器框架): 创建了aurora postgreSQL集群 已将aurora postgreSQL群集连接到应用程序同步 已在应用程序同步中创建graphql架构 身份验证类型为-API密钥 应用程序同步配置的形式如下(): 我的graphql模式取自此处() } } } } } } } } my get

我遇到了应用程序同步的问题,其中数据源是关系数据库

所以,我的目标是将Aurora无服务器postgresql集群与app sync作为数据源连接起来,并使其正常工作

我执行的步骤(全部通过无服务器框架):

创建了aurora postgreSQL集群

已将aurora postgreSQL群集连接到应用程序同步

已在应用程序同步中创建graphql架构

身份验证类型为-API密钥

应用程序同步配置的形式如下():

我的graphql模式取自此处()

}

}

}

}

}

}

}

}

my getPetrequest.vtl:

{
"version": "2018-05-29",
    "statements": [
        $util.toJson("select * from Pets WHERE id='$ctx.args.id'")
]
}

my getPetresponse.vtl:

$utils.toJson($utils.rds.toJsonObject($ctx.result)[0][0])
部署的一切都非常完美,比如集群Arn(dbClusterIdentifier)、带应用同步数据源的AWSSecretsStoreArn数据库名称、带模式的解析器

并在部署的输出中获得带有api键的GraphQLAPI

在此之后,我通过rds cluster的查询编辑器创建了一个包含列id、类型、价格和一条记录的表Pets

所以现在,当我试图在AppSync的控制台中进行查询时,得到的值为null。 查询是:

    query {getPet(id: "1"){id type price }}
也尝试使用NodeJS代码,但结果相同



// url of your GraphQL API. If you configured a custom domain, you could use that instead


    const url =

  "https://z4#############.appsync-api.us-east-1.amazonaws.com/graphql";


// api key of your GraphQL API

const apiKey = "da2-7by6############";


// ID of the post you wanna query

const id = "1";


fetch(url, {

  method: "POST",

  headers: {

    "Content-Type": "application/json",

    "x-api-key": apiKey

  },

  body: JSON.stringify({

    query: `query {getPet(id: "${id}"){id}}`

  })

})

  .then(res => res.text())

  .then(post => console.log(post));```
any help how to make it working.

因此,问题在于appsync采用的默认iam角色策略。 默认情况下,appsync将使用以下策略创建iam角色

- Effect: Allow
  Action:
    - secretsmanager:GetSecretValue
  Resource: "your resource mentioned"
- Effect: Allow
  Action:
    - rds-data:DeleteItems
    - rds-data:ExecuteSql
    - rds-data:GetItems
    - rds-data:InsertItems
    - rds-data:UpdateItems
  Resource: "your resource mentioned"
现在这里缺少一件事,那就是

- rds-data:ExecuteStatement
所以,我用失踪警察创建了新的iam角色,并将其附加到appsync,它对我有效

    enum PetType {
dog
cat
fish
bird
gecko
    type Query {
getPet(id: ID!): Pet
listPets: [Pet]
listPetsByPriceRange(min: Float, max: Float): [Pet]
    schema {
query: Query
mutation: Mutation
{
"version": "2018-05-29",
    "statements": [
        $util.toJson("select * from Pets WHERE id='$ctx.args.id'")
]
$utils.toJson($utils.rds.toJsonObject($ctx.result)[0][0])
    query {getPet(id: "1"){id type price }}


// url of your GraphQL API. If you configured a custom domain, you could use that instead


    const url =

  "https://z4#############.appsync-api.us-east-1.amazonaws.com/graphql";


// api key of your GraphQL API

const apiKey = "da2-7by6############";


// ID of the post you wanna query

const id = "1";


fetch(url, {

  method: "POST",

  headers: {

    "Content-Type": "application/json",

    "x-api-key": apiKey

  },

  body: JSON.stringify({

    query: `query {getPet(id: "${id}"){id}}`

  })

})

  .then(res => res.text())

  .then(post => console.log(post));```
any help how to make it working.
- Effect: Allow
  Action:
    - secretsmanager:GetSecretValue
  Resource: "your resource mentioned"
- Effect: Allow
  Action:
    - rds-data:DeleteItems
    - rds-data:ExecuteSql
    - rds-data:GetItems
    - rds-data:InsertItems
    - rds-data:UpdateItems
  Resource: "your resource mentioned"
- rds-data:ExecuteStatement