New Answer:
Amplify now has documentation on this use case: https://docs.amplify.aws/cli/usage/mock#connecting-to-a-mock-model-table
You can set environment variables for mock that will point the DDB client in the mock lambda to the local DDB instance
=====================================================================
Original Answer:
After some digging into the Amplify CLI code, I have found a solution that will work for now.
Here is where amplify mock
initializes DynamoDB Local. As you can see, it does not set the --sharedDb
flag which based on the docs means that the created database files will be prefixed with the access key id of the request and then the region. The access key id of requests from Amplify will be "fake" and the region is "us-fake-1" as defined here. Furthermore, the port of the DynamoDB Local instance started by Amplify is 62224 defined here.
Therefore, to connect to the tables that are created by Amplify, the following DynamoDB config is needed
const ddb = new AWS.DynamoDB({
region: 'us-fake-1',
endpoint: "http://172.16.123.1:62224/",
accessKeyId: "fake",
secretAccessKey: "fake"
})
If you want to use the AWS CLI with the tables created by Amplify, you'll have to create a new profile with the region and access keys above.
I'll still need to do some additional work to figure out a good way to have those config values switch between the local mock values and the actual ones, but this unblocks local testing for now.
As for another question that I had about where AWS::Region of "us-east-1-fake" was being set, that gets set here but it does not appear to be used anywhere else. ie, it gets set as a placeholder value when running amplify mock
but using it as a region in other places for testing locally doesn't seem to work.