AWS DataExchange API请求返回404: Asset not found问题排查求助
排查AWS DataExchange API返回404: Asset not found问题
问题背景
使用AWS Node.js的aws-sdk和@aws-sdk/client-dataexchange调用AWS DataExchange提供商的API时,所有查询均返回404: Asset not found。已确认订阅该API,且AWS凭证、策略、IAM密钥均具备访问权限,需排查请求与API规范的不符之处。
返回的错误响应
{ "404": "Asset not found", "$fault": "client", "$metadata": { "httpStatusCode": 404, "requestId": "b7e6e691-xxxxxxx7657201138a4", "extendedRequestId": undefined, "cfId": "dBQBwlCE8cXp4--xxxxxxxxxxx3j2lTfxywUezCPEA6nusJCJg==", "attempts": 1, "totalRetryDelay": 0 }, "ResourceType": "ASSET", "ResourceId": "e055c882bde1fa3xxxxxxxxx" }
当前请求Body内容
Body: JSON.stringify({ "description": "GraphQL query for the Ursa Space Imagery Catalog.", "content": { "application/graphql": { "schema": { "$ref": "#/components/schemas/CatalogSearchRequest" }, "query": { "description": "Limit the number of records in a response.", "value": "{\n availablemetadatarecord(\n limit: 20\n content: { catalogProperties: { vendor: { eq: \"ICEYE\" } } }\n ) {\n assignedId\n }\n}\n" } } }, "required": true }),
提供商API规范
{ "openapi": "3.0.1", "info": { "title": "image-services", "description": "API Gateway for integration of Platform Services into AWS Data Exchange", "version": "2022-03-03T20:04:18Z" }, "servers": [ { "url": "" } ], "paths": { "/psdm/graphql": { "post": { "requestBody": { "description": "GraphQL query for the Catalog in the form of:\n\n `{\n availablemetadatarecord(\n QUERYPARAMS\n ) { \n FIELDLIST\n } \n }`\n", "content": { "application/graphql": { "schema": { "$ref": "#/components/schemas/CatalogSearchRequest" }, "examples": { "Limit returned data": { "description": "Limit the number of records in a response.\n\nIn your query, simply specify `limit: <int>` \n", "value": "{\n availablemetadatarecord(\n limit: 10\n content: { catalogProperties: { vendor: { eq: \"EYE\" } } }\n ) {\n assignedId\n }\n}\n" } } } }, "required": true }, "responses": { "200": { "description": "200 response", "content": { "application/json": { "schema": { "$ref": "#/components/schemas/CatalogSearchResponse" } } } } }, "security": [ { "sigv4": [] } ] } } }, "components": { "schemas": { "CatalogSearchRequest": { "title": "CatalogSearchRequest", "type": "object" }, "CatalogSearchResponse": { "title": "Catalog Search Response", "required": [ "data", "paginationInfo" ], "type": "object", "properties": { "paginationInfo": { "type": "object", "properties": { "recordsInPage": { "type": "integer" }, "nextOffset": { "type": "integer" } } }, "data": { "type": "object", "properties": { "availablemetadatarecord": { "type": "array", "description": "Records returned by query", "items": { "type": "object" } } } } } } }, "securitySchemes": { "sigv4": { "type": "apiKey", "name": "Authorization", "in": "header", "x-amazon-apigateway-authtype": "awsSigv4" } } } }
排查与修正要点
请求Body格式完全不符合规范
API规范中/psdm/graphql的POST请求,application/graphql类型的请求体直接是GraphQL查询字符串,无需嵌套多层JSON结构。当前请求将查询放在content.application/graphql.query.value的嵌套结构中,这是核心错误。验证Asset ID正确性
错误响应返回的ResourceId需确认是否为订阅API对应的正确Asset ID,排查是否存在拼写错误或使用了过期/不存在的ID。确认请求路径与Content-Type
确保请求路径为/psdm/graphql,同时请求头Content-Type设置为application/graphql,而非application/json。
修正后的请求示例
const { DataExchangeClient, SendApiAssetCommand } = require("@aws-sdk/client-dataexchange"); // 直接使用GraphQL查询字符串作为请求Body const graphqlQuery = `{ availablemetadatarecord( limit: 20 content: { catalogProperties: { vendor: { eq: "ICEYE" } } } ) { assignedId } }`; const client = new DataExchangeClient({ region: "你的AWS区域" }); const command = new SendApiAssetCommand({ AssetId: "正确的Asset ID", DataSetId: "对应数据集ID", RevisionId: "对应版本ID", Body: graphqlQuery, Headers: { "Content-Type": "application/graphql" } }); // 发送请求 const response = await client.send(command); console.log(response);
内容的提问来源于stack exchange,提问作者Vakindu
相关产品推荐
相关产品推荐

