2

I used @model annotation to create a table and a function that adds an entry in that table as a PostAuthentication Trigger to User pool. It works fine when I push it to AWS. But facing some issues in testing it locally.

MockData is there in amplify/mock-data/dynamodb/fake_us-fake-1.db

In the function/function_name/index.js

import AWS from 'aws-sdk';
import { Logger } from '@dev.tools.thinkclear/common-util';

const options = {
  region: 'us-fake-1',
  endpoint: "<local_url>:62224/",
  accessKeyId: "fake",
  secretAccessKey: "fake"
};

AWS.config.update( {
  region: 'us-fake-1',
  endpoint: "<local_url>:62224/",
  accessKeyId: "fake",
  secretAccessKey: "fake"
});

const dynamoDBClientVar = new AWS.DynamoDB.DocumentClient(options);
// Some Data params 
const data = await dynamoDBClient.put(params).promise();

local_url is the same url where amplify mock api is running . Changed the port to 62224 for dynamodb.

amplify mock function function_name

It's throwing Error: NetworkingError: connect ECONNREFUSED error.

Checked this answer for reference: https://stackoverflow.com/a/58925502/4578915

Shiva MSK
  • 484
  • 1
  • 6
  • 16
  • Have you watched this video? https://youtu.be/OxrHplxZ8BA (Mocking and Testing Serverless APIs with AWS Amplify - AWS Online Tech Talks) – Si Thu Dec 16 '20 at 02:29

1 Answers1

1

I have configured it and it's working fine for me,

const AWS = require('aws-sdk');

// Local
const dynamoDb = new AWS.DynamoDB.DocumentClient({
    region: 'us-fake-1',
    endpoint: "http://localhost:62224/",
    accessKeyId: "fake",
    secretAccessKey: "fake"
});

// Live
// const dynamoDb = new AWS.DynamoDB.DocumentClient();

Please with the above setting, if you have any query please dropped a message.

Ansari Maksud
  • 316
  • 2
  • 5
  • 20