AppSync S3Object检索 [英] AppSync S3Object retrieval

查看:66
本文介绍了AppSync S3Object检索的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

根据提供的教程,我的文件当前正在上传到s3存储桶.

My files are currently being uploaded to an s3 bucket according to the tutorials provided.

我有一个Post类型,其文件字段指向S3Object. S3Object具有存储区,键和区域的值.

I have a Post type with a file field pointing to an S3Object. S3Object has the values of bucket, key, and region.

我想允许我的用户下载他们上传的文件,但是我无法通过查询访问Post>文件.这意味着我无法获得下载URL.

I want to allow my users to download their uploaded files, but I cannot access Post > file through a query. This means I cannot get the download URL.

现在,DynamoDB在上传时将以下内容存储为文件(我在这里更改了值): {"s3":{"key":"id.pdf","bucket":"my-bucket","region":"my-region"}}

Right now, DynamoDB stores the following for file upon upload (I've changed the values here): {"s3":{"key":"id.pdf","bucket":"my-bucket","region":"my-region"}}

我的Post解析器>文件看起来像这样: { "version": "2017-02-28", "operation": "GetItem", "key": { "id": $util.dynamodb.toDynamoDBJson($ctx.source.id), } }

My resolver for Post > file looks like this: { "version": "2017-02-28", "operation": "GetItem", "key": { "id": $util.dynamodb.toDynamoDBJson($ctx.source.id), } }

响应模板: $util.dynamodb.fromS3ObjectJson($ctx.result.file)

运行查询时,出现以下错误: Error: GraphQL error: Unable to convert {bucket=my-bucket, region=my-region, key=id.pdf} to class java.lang.Object.

When I run the query, I get the following error: Error: GraphQL error: Unable to convert {bucket=my-bucket, region=my-region, key=id.pdf} to class java.lang.Object.

推荐答案

我相信您需要在对$util.toJson()的调用中包装$util.dynamodb.fromS3ObjectJson($ctx.result.file).您能否将响应映射模板更改为$util.toJson($util.dynamodb.fromS3ObjectJson($ctx.result.file))并查看是否有效?

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?

作为一个旁注,我认为您可以实现期望的效果,而无需从Post.file解析器中再次调用DynamoDB.创建一个无"数据源,并更改Post.file解析器以使用它.您可以提供准系统请求映射模板,例如

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": {} }

{ "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))

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

由于在解析Post.file字段时将已经获取了该帖子,所以该信息将已在源中可用.如果需要从与Post对象不同的表中获取S3Link,则需要第二个DynamoDB调用.

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.

希望这会有所帮助,让我知道对$ util.toJson的调用是否可以解决此问题.

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

谢谢

这篇关于AppSync S3Object检索的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆