AppSync 中的 S3Object GraphQL 类型与 Lambda 数据源?

S3Object GraphQL type in AppSync with Lambda datasource?

AppSync 中可用的 S3Object GraphQL 类型(请参阅 https://docs.aws.amazon.com/appsync/latest/devguide/building-a-client-app-ios.html 中的复杂对象部分)是否与 dynamoDB 相关联,或者它是否可以与 Lambda 数据源一起使用(比如连接到 mongoDB)?

来自上面链接的 AWS 文档...

type Post {
    id: ID!
    author: String!
    title: String
    content: String
    url: String
    ups: Int
    downs: Int
    file: S3Object
    version: Int!
}

type S3Object {
    bucket: String!
    key: String!
    region: String!
}

input S3ObjectInput {
    bucket: String!
    key: String!
    region: String!
    localUri: String
    mimeType: String
}

我没试过这个,但你应该能够做你想完成的事情,并使用 reads/writes 到 Mongo 甚至 RDS 等其他东西的 Lambda 数据源. AppSync 需要 S3ObjectS3ObjectInput 的 GraphQL 类型以及上面列出的 bucket 等字段,以便客户端 SDK 和代码生成器正确构建对象,但是 S3Link 功能已完成在解析器本身中用于读取和写入。您可以将其移动到 Lambda 中的逻辑层。

如果您查看 https://docs.aws.amazon.com/appsync/latest/devguide/resolver-context-reference.html#dynamodb-helpers-in-util-dynamodb,您将看到映射函数签名和输出:

$util.dynamodb.toS3Object(String key, String bucket, String region) : Map
$util.dynamodb.toS3ObjectJson(String key, String bucket, String region) : String
$util.dynamodb.toS3Object(String key, String bucket, String region, String version) : Map
$util.dynamodb.toS3ObjectJson(String key, String bucket, String region, String version) : String
$util.dynamodb.fromS3ObjectJson(String) : Map

因此,如果您想将此逻辑移动到 write/read 到 Lambda 中,那是完全可能的。如果你站起来这个样本,你将能够对其进行逆向工程:https://github.com/aws-samples/aws-amplify-graphql