aws / aws-cdk

The AWS Cloud Development Kit is a framework for defining cloud infrastructure in code
https://aws.amazon.com/cdk
Apache License 2.0
11.72k stars 3.94k forks source link

(appsync): does not work with ServerlessCluster - This API is deprecated and not available. Use ExecuteStatement API instead #12735

Closed BerndWessels closed 3 years ago

BerndWessels commented 3 years ago

It seems that AppSync cannot access Aurora Serverless Postgres Cluster via DataAPI DataSource Resolvers anymore.

I've been following all of the AWS tutorials and examples I could find - using the CDK as well as doing it manually

I've tried everything from scratch with whatever is the latest of everything as of 28/01/2021.

I always get

"error": {
            "message": "RDSHttp:{\"message\":\"This API is deprecated and not available. Use ExecuteStatement API instead\"}",
            "type": "400 Bad Request"
        },

image

Reproduction Steps

manually: https://docs.aws.amazon.com/appsync/latest/devguide/tutorial-rds-resolvers.html

CDK:

import * as cdk from "@aws-cdk/core";
import * as appsync from "@aws-cdk/aws-appsync";
import * as cognito from "@aws-cdk/aws-cognito";
import * as rds from "@aws-cdk/aws-rds";
import * as secretsManager from "@aws-cdk/aws-secretsmanager";

/**
 * Stack Properties
 */
export interface ApiStackProps extends cdk.StackProps {
  readonly databaseCluster: rds.ServerlessCluster;
  readonly userPool: cognito.UserPool;
}

/**
 * Stack
 */
export class ApiStack extends cdk.Stack {
  /**
   * Outputs
   */
  public readonly api: appsync.GraphqlApi;

  /**
   * Construct
   */
  constructor(scope: cdk.Construct, id: string, props: ApiStackProps) {
    super(scope, id, props);

    /**
     * Defaults
     */
    const { databaseCluster, userPool } = props;

    /**
     * GraphQL Api
     */
    const api = new appsync.GraphqlApi(this, "Api", {
      authorizationConfig: {
        defaultAuthorization: {
          authorizationType: appsync.AuthorizationType.USER_POOL,
          userPoolConfig: {
            userPool: userPool,
          },
        },
      },
      name: "my-product-appsync-api",
      schema: appsync.Schema.fromAsset("../graphql/schema.graphql"),
    });

    /**
     * Database Data Source
     */
    const databaseDataSource = api.addRdsDataSource(
      "DatabaseDataSource",
      (databaseCluster as unknown) as rds.IDatabaseCluster,
      databaseCluster.secret as secretsManager.ISecret,
      {
        description: "Serverless Aurora RDS Database Data Source",
        name: "DatabaseDataSource",
      }
    );

    /**
     * Resolvers
     */
    databaseDataSource.createResolver({
      fieldName: "name",
      requestMappingTemplate: appsync.MappingTemplate.fromString(`
      {
          "version": "2018-05-29",
          "statements": [
              "SELECT current_database() as name"
          ]
      }        
      `),
      responseMappingTemplate: appsync.MappingTemplate.fromString(`
        #if($ctx.error)
            $utils.error($ctx.error.message, $ctx.error.type)
        #end

        $utils.toJson($utils.rds.toJsonObject($ctx.result)[0])
      `),
      typeName: "Query",
    });

    /**
     * Outputs
     */
    this.api = api;
  }
}

What did you expect to happen?

Query will execute without errors.

What actually happened?

Error response

"error": {
            "message": "RDSHttp:{\"message\":\"This API is deprecated and not available. Use ExecuteStatement API instead\"}",
            "type": "400 Bad Request"
        },

Environment

aws-cli/1.18.217 Python/2.7.18 Linux/4.14.214-160.339.amzn2.x86_64 botocore/1.19.57 node v10.23.1 aws cloud 9 aws console


"@aws-cdk/aws-appsync": "^1.86.0",
"@aws-cdk/aws-cognito": "^1.86.0",
"@aws-cdk/aws-ec2": "^1.86.0",
"@aws-cdk/aws-iam": "^1.86.0",
"@aws-cdk/aws-rds": "^1.86.0",
"@aws-cdk/core": "1.86.0",

This is :bug: Bug Report
MrArnoldPalmer commented 3 years ago

Thanks for the report! Asking around, this seems like a bug with AppSync that has since been fixed. If you're still having this issue reopen the issue and we will look into it more.

github-actions[bot] commented 3 years ago

⚠️COMMENT VISIBILITY WARNING⚠️

Comments on closed issues are hard for our team to see. If you need more assistance, please either tag a team member or open a new issue that references this one. If you wish to keep having a conversation with other community members under this issue feel free to do so.