How to use where clause in Knex
Create refunds with Stripe
Load HTML with Cheerio
How to send POST request with Axios
Find intersection of array in Lodash
Powered by Official white Bloop logo with a period

Terms / Privacy / Search / Support

  • // Create username and password secret for DB Cluster
    const secret = new rds.DatabaseSecret(this, 'AuroraSecret', {
      username: 'clusteradmin',
    });
    
    // The VPC to place the cluster in
    const vpc = new ec2.Vpc(this, 'AuroraVpc');
    
    // Create the serverless cluster, provide all values needed to customise the database.
    const cluster = new rds.ServerlessCluster(this, 'AuroraCluster', {
      engine: rds.DatabaseClusterEngine.AURORA_MYSQL,
      vpc,
      credentials: { username: 'clusteradmin' },
      clusterIdentifier: 'db-endpoint-test',
      defaultDatabaseName: 'demos',
    });
    
    // Build a data source for AppSync to access the database.
    declare const api: appsync.GraphqlApi;
    const rdsDS = api.addRdsDataSource('rds', cluster, secret, 'demos');
    
    // Set up a resolver for an RDS query.
    rdsDS.createResolver({
      typeName: 'Query',
      fieldName: 'getDemosRds',
      requestMappingTemplate: appsync.MappingTemplate.fromString(`
      {
        "version": "2018-05-29",
        "statements": [
          "SELECT * FROM demos"
        ]
      }
      `),
      responseMappingTemplate: appsync.MappingTemplate.fromString(`
        $utils.toJson($utils.rds.toJsonObject($ctx.result)[0])
      `),
    });
    
    // Set up a resolver for an RDS mutation.
    rdsDS.createResolver({
      typeName: 'Mutation',
      fieldName: 'addDemoRds',
      requestMappingTemplate: appsync.MappingTemplate.fromString(`
      {
        "version": "2018-05-29",
        "statements": [
          "INSERT INTO demos VALUES (:id, :version)",
          "SELECT * WHERE id = :id"
        ],
        "variableMap": {
          ":id": $util.toJson($util.autoId()),
          ":version": $util.toJson($ctx.args.version)
        }
      }
      `),
      responseMappingTemplate: appsync.MappingTemplate.fromString(`
        $utils.toJson($utils.rds.toJsonObject($ctx.result)[1][0])
      `),
    });
    
    Docs
  • import * as es from '@aws-cdk/aws-elasticsearch';
    
    const user = new iam.User(this, 'User');
    const domain = new es.Domain(this, 'Domain', {
      version: es.ElasticsearchVersion.V7_1,
      removalPolicy: RemovalPolicy.DESTROY,
      fineGrainedAccessControl: { masterUserArn: user.userArn },
      encryptionAtRest: { enabled: true },
      nodeToNodeEncryption: true,
      enforceHttps: true,
    });
    
    declare const api: appsync.GraphqlApi;
    const ds = api.addElasticsearchDataSource('ds', domain);
    
    ds.createResolver({
      typeName: 'Query',
      fieldName: 'getTests',
      requestMappingTemplate: appsync.MappingTemplate.fromString(JSON.stringify({
        version: '2017-02-28',
        operation: 'GET',
        path: '/id/post/_search',
        params: {
          headers: {},
          queryString: {},
          body: { from: 0, size: 50 },
        },
      })),
      responseMappingTemplate: appsync.MappingTemplate.fromString(`[
        #foreach($entry in $context.result.hits.hits)
        #if( $velocityCount > 1 ) , #end
        $utils.toJson($entry.get("_source"))
        #end
      ]`),
    });
    
    Docs
  • declare const api: appsync.GraphqlApi;
    declare const appsyncFunction: appsync.AppsyncFunction;
    
    const pipelineResolver = new appsync.Resolver(this, 'pipeline', {
      api,
      dataSource: api.addNoneDataSource('none'),
      typeName: 'typeName',
      fieldName: 'fieldName',
      requestMappingTemplate: appsync.MappingTemplate.fromFile('beforeRequest.vtl'),
      pipelineConfig: [appsyncFunction],
      responseMappingTemplate: appsync.MappingTemplate.fromFile('afterResponse.vtl'),
    });
    
    Docs
  • const api = new appsync.GraphqlApi(this, 'Api', {
      name: 'demo',
      schema: appsync.Schema.fromAsset(path.join(__dirname, 'schema.graphql')),
      authorizationConfig: {
        defaultAuthorization: {
          authorizationType: appsync.AuthorizationType.IAM,
        },
      },
      xrayEnabled: true,
    });
    
    const demoTable = new dynamodb.Table(this, 'DemoTable', {
      partitionKey: {
        name: 'id',
        type: dynamodb.AttributeType.STRING,
      },
    });
    
    const demoDS = api.addDynamoDbDataSource('demoDataSource', demoTable);
    
    // Resolver for the Query "getDemos" that scans the DynamoDb table and returns the entire list.
    demoDS.createResolver({
      typeName: 'Query',
      fieldName: 'getDemos',
      requestMappingTemplate: appsync.MappingTemplate.dynamoDbScanTable(),
      responseMappingTemplate: appsync.MappingTemplate.dynamoDbResultList(),
    });
    
    // Resolver for the Mutation "addDemo" that puts the item into the DynamoDb table.
    demoDS.createResolver({
      typeName: 'Mutation',
      fieldName: 'addDemo',
      requestMappingTemplate: appsync.MappingTemplate.dynamoDbPutItem(
        appsync.PrimaryKey.partition('id').auto(),
        appsync.Values.projecting('input'),
      ),
      responseMappingTemplate: appsync.MappingTemplate.dynamoDbResultItem(),
    });
    
    Docs
  • const api = new appsync.GraphqlApi(this, 'api', {
      name: 'api',
      schema: appsync.Schema.fromAsset(path.join(__dirname, 'schema.graphql')),
    });
    
    const httpDs = api.addHttpDataSource(
      'ds',
      'https://states.amazonaws.com',
      {
        name: 'httpDsWithStepF',
        description: 'from appsync to StepFunctions Workflow',
        authorizationConfig: {
          signingRegion: 'us-east-1',
          signingServiceName: 'states',
        }
      }
    );
    
    httpDs.createResolver({
      typeName: 'Mutation',
      fieldName: 'callStepFunction',
      requestMappingTemplate: appsync.MappingTemplate.fromFile('request.vtl'),
      responseMappingTemplate: appsync.MappingTemplate.fromFile('response.vtl'),
    });
    
    Docs
  • Powered by Official black Bloop logo with a period
    download the IDE extension

    View other examples