AppSync S3Object retrieval

风格不统一 提交于 2019-12-04 12:45:08

I believe you need to wrap $util.dynamodb.fromS3ObjectJson($ctx.result.file) in a call to $util.toJson(). Can you kindly change the response mapping template to $util.toJson($util.dynamodb.fromS3ObjectJson($ctx.result.file)) and see if that works?

As a side-note, I think you can achieve the desired effect without making a second call to DynamoDB from the Post.file resolver. Create a "None" datasource and change the Post.file resolver to use it. You can provide a barebones request mapping template such as

{ "version": "2017-02-28", "payload": {} }

and can then change your response mapping template to use the source instead of the result.

$util.toJson($util.dynamodb.fromS3ObjectJson($ctx.source.file))

Since the post will already have been fetched by the time the Post.file field is being resolved the information will already be available in the source. If you needed to fetch the S3Link from a different table than the Post objects then you would need a second DynamoDB call.

Hope this helps and let me know if the call to $util.toJson fixes the issue.

Thanks

Göran Svensson

This solution does not work with a Local datasource of type none any longer, or it's not possible to do this in the aws console at least.

I got the:

MappingTemplate error: Value for field '$[operation]' not found

every time I tried this solution. When I changed datasource to the one that has the file field and used the request resolver:

{
    "version": "2017-02-28",
    "operation": "GetItem",
    "key": {
        "id": $util.dynamodb.toDynamoDBJson($ctx.source.id),
    }
}

and the response resolver:

$util.toJson($util.dynamodb.fromS3ObjectJson($context.source.file))

It worked as it should.

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!