1

I am trying to upload images to my S3 bucket when sending chat messages to my Aurora Database using AppSync with Lambda configured as it's data source.

My resolver for the mutation is:

{
    "version": "2017-02-28",
    "operation": "Invoke",
    "payload": {
        "field": "createMessage",
        "arguments":  $utils.toJson($context.arguments)
    }
}

The messages are being saved correctly in the database however the S3 image data files are not being saved in my S3 bucket. I believe I have configured everything correctly except for the resolver which I am not sure about.

John Rotenstein
  • 241,921
  • 22
  • 380
  • 470
alionthego
  • 8,508
  • 9
  • 52
  • 125

1 Answers1

2

Uploading files with AppSync when data source is lambda is basically the same as for every other data source and it does not depend on resolvers.

Just make sure you have your credentials for complex objects set up (JS example using Amplify library for authorization):

import { Auth } from 'aws-amplify'
const client = new AWSAppSyncClient({
    url: /*your endpoint*/,
    region: /*your region*/,
    complexObjectsCredentials: () => Auth.currentCredentials(),
})

And also you need to provide S3 complex object as an input type for your mutation:

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

Everything else will work just fine even with lambda data source. Here you can find more information related to your question(in that example dynamoDB is used but it is basically the same for lambda: https://stackoverflow.com/a/50218870/9359164

AlpacaGoesCrazy
  • 796
  • 8
  • 14