title: Aurora Serverless Postgresql as data source for app sync
body: <p>I was facing problem with app sync where data source is Relational Database. </p>
  
  <p>So, my goal is to connect Aurora server less postgresql cluster with app sync as data source and get it working.</p>
  
  <p>Steps I have performed(all via server-less framework) :</p>
  
  <p>Created aurora postgreSQL cluster.</p>
  
  <p>Connected aurora postgreSQL cluster to app sync.</p>
  
  <p>Created graphql Schema in app sync.</p>
  
  <p>Authentication Type is - API key.</p>
  
  <p>app sync configuration taken form here( <a href="https://github.com/serverless-components/aws-app-sync#data-sources--templates" rel="nofollow noreferrer">https://github.com/serverless-components/aws-app-sync#data-sources--templates</a> ). : </p>
  
  <pre><code>appSync:
  name: Posts
  authenticationType: API_KEY
  apiKeys:
    - myApiKey
  dataSources:
    - type: RELATIONAL_DATABASE
      name: Posts
      config:
        awsSecretStoreArn: 
          Ref: SecretsManager
        databaseName: "mydatabase"
        dbClusterIdentifier: 
          Ref: AuroraRDSCluster
  schema: schema.graphql
  mappingTemplates:
    - dataSource: Posts
      type: Query
      field: getPet
      request: "request.vtl"
      response: "response.vtl"
    - dataSource: Posts
      type: Query
      field: listPets
      request: "listPets_request.vtl"
      response: "listPets_response.vtl"
  </code></pre>
  
  <p>my graphql schema taken from here( <a href="https://docs.aws.amazon.com/appsync/latest/devguide/tutorial-rds-resolvers.html" rel="nofollow noreferrer">https://docs.aws.amazon.com/appsync/latest/devguide/tutorial-rds-resolvers.html</a> )</p>
  
  <pre><code>    type Mutation {
  createPet(input: CreatePetInput!): Pet
  updatePet(input: UpdatePetInput!): Pet
  deletePet(input: DeletePetInput!): Pet
  </code></pre>
  
  <p>}</p>
  
  <pre><code>    input CreatePetInput {
  type: PetType
  price: Float!
  </code></pre>
  
  <p>}</p>
  
  <pre><code>    input UpdatePetInput {id: ID!
  type: PetType
  price: Float!
  </code></pre>
  
  <p>}</p>
  
  <pre><code>    input DeletePetInput {
  id: ID!
  </code></pre>
  
  <p>}</p>
  
  <pre><code>    type Pet {
  id: ID!
  type: PetType
  price: Float
  </code></pre>
  
  <p>}</p>
  
  <pre><code>    enum PetType {
  dog
  cat
  fish
  bird
  gecko
  </code></pre>
  
  <p>}</p>
  
  <pre><code>    type Query {
  getPet(id: ID!): Pet
  listPets: [Pet]
  listPetsByPriceRange(min: Float, max: Float): [Pet]
  </code></pre>
  
  <p>}</p>
  
  <pre><code>    schema {
  query: Query
  mutation: Mutation
  </code></pre>
  
  <p>} </p>
  
  <p><strong>my getPet</strong> request.vtl :</p>
  
  <pre><code>{
  "version": "2018-05-29",
      "statements": [
          $util.toJson("select * from Pets WHERE id='$ctx.args.id'")
  ]
  </code></pre>
  
  <p>}</p>
  
  <p><strong>my getPet</strong> response.vtl: </p>
  
  <pre><code>$utils.toJson($utils.rds.toJsonObject($ctx.result)[0][0])
  </code></pre>
  
  <p>and everything deployed perfectly like cluster Arn(dbClusterIdentifier) , awsSecretStoreArn database name with app sync datasource , resolvers with schema.</p>
  
  <p>And got graphql api with api key in output of deployment.</p>
  
  <p>After this I have created a table Pets with column id, type, price with one record through query editor of rds cluster. </p>
  
  <p>So now , when I was trying to query in console of app sync, I was getting value as null.
  query is :</p>
  
  <pre><code>    query {getPet(id: "1"){id type price }}
  </code></pre>
  
  <p>tried with node js code also but same result.</p>
  
  <pre><code>
  
  // 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 =&gt; res.text())
  
    .then(post =&gt; console.log(post));```
  any help how to make it working.
  </code></pre>