appsync graphql query fails with error type OpenSearch:UserIllegalArgumentException

0

we are trying to add an OpenSearch datasource to our existing AppSync setup. all other datasources for AppSync have been DynamDB up to this point

is this error type indicating a problem with the resolver mapping templates or a problem re AppSync accessing OpenSearch ie misconfigured access policies?

we are using the nodejs CDK to deploy via CodePipeline

we have added an OpenSearch Domain, and it is being populated by a lambda listening for writes to a DynamoDB table - this part is working

we have created an OpenSearch Datasource, and created a resolver using the following as request and response mapping templates

const requestTemplate = `{
  "version":"2017-02-28",
  "operation":"GET",
  "path":"/id/shipments/_search",
  "params":{
      "body":{
          "from":0,
          "to": 20
      }
  }
}`;

const responseTemplate = `{
  "shipments": [
    #foreach($entry in $context.result.hits.hits)
      #if( $velocityCount > 1 ) , #end
      $utils.toJson($entry.get("_source"))
    #end
  ],
  "total": -1
}`;

const datasourceId = `ShipmentsListDatasource`;
const datasource = new appsync.OpenSearchDataSource(
  this,
  getId(datasourceId, this.props),
  {
    domain: this.openSearchDomain,
    api: this.api,
  }
);

datasource.createResolver({
  typeName: GraphQLTypeName.Query,
  fieldName: "listShipments",
  requestMappingTemplate: appsync.MappingTemplate.fromString(
    requestTemplate
  ),
  responseMappingTemplate: appsync.MappingTemplate.fromString(
    responseTemplate
  ),
});

access to the OpenSearch domain has been configured like this

private configureOpenSearch() {
    const openSearchAppsyncRole = new iam.Role(
      this,
      "a-role-name-here",
      {
        assumedBy: new iam.ServicePrincipal("appsync.amazonaws.com"),
      }
    );

    const lambdaPolicyStatement = new iam.PolicyStatement({
      actions: ["es:*"],
      resources: [`${this.openSearchDomain.domainArn}/*`],
      principals: [new iam.ArnPrincipal(this.baseStack.lambdaRole.roleArn)],
    });

    const rolePolicyStatement = new iam.PolicyStatement({
      actions: ["es:*"],
      resources: [`${this.openSearchDomain.domainArn}/*`],
      effect: iam.Effect.ALLOW,
      notPrincipals: [openSearchAppsyncRole]
    })

    this.openSearchDomain.addAccessPolicies(lambdaPolicyStatement, rolePolicyStatement);
    this.openSearchDomain.grantRead(openSearchAppsyncRole);
    this.openSearchDomain.grantIndexReadWrite(
      "id",
      this.shipmentsOpenSearchLambda
    );
  }

any requests to the graphql endpoint for this particular query return the following

{
	"data": null,
	"errors": [{
		"path": ["listShipments"],
		"data": null,
		"errorType": "OpenSearch:UserIllegalArgumentException",
		"errorInfo": null,
		"locations": [{
			"line": 3,
			"column": 5,
			"sourceName": null
		}],
		"message": "OpenSearch responded with an error: Bad Request"
	}]
}
답변 없음

로그인하지 않았습니다. 로그인해야 답변을 게시할 수 있습니다.

좋은 답변은 질문에 명확하게 답하고 건설적인 피드백을 제공하며 질문자의 전문적인 성장을 장려합니다.

질문 답변하기에 대한 가이드라인

관련 콘텐츠