Get #Amazon #Prime for this #holiday #amazonprime #christmas #2019

How to import #aws sdk #sqs from #amplify library?

If you are using aws Amplify library (I use 0.4.3 at the moment) in an Angular project and trying to use Simple Queue Service(SQS) from aws-sdk library, you may run into some problem trying to import SQS service.


If you do it the way they do it in the following example, you may get some errors importing SQS:
import Route53 from 'aws-sdk/clients/route53';

Auth.currentCredentials()
  .then(credentials => {
    const route53 = new Route53({
      apiVersion: '2013-04-01',
      credentials: Auth.essentialCredentials(credentials)
    });

    // more code working with route53 object
    // route53.changeResourceRecordSets();
  })
source: Amplify doc

Errors that I got in the process of making it work are these:
import fails with 'no default export'

Cannot use 'new' with an expression whose type lacks a call or construct signature.

Attempts:

1)
I have tried suggestions by adding the following compilerOptions according to suggestions in this Typescript-React-Starter Github thread.
"compilerOptions": {
  "allowSyntheticDefaultImports": true,
  "esModuleInterop": true,
  "module": "es2015",
}

I still couldn't import using the import syntax

import SQS from 'aws-sdk/clients/sqs';

2)
I tried to import using the following syntax.

import * as SQS from 'aws-sdk/clients/sqs';

With this, I didn't get 'no default export' error but this new error:

Cannot use 'new' with an expression whose type lacks a call or construct signature.

I, then, read the discussions on these 2 Github threads which seem to suggest the change export syntax.
i) https://github.com/fengyuanchen/cropperjs/issues/305
ii) https://github.com/krisk/Fuse/issues/137

If you modify aws-sdk/clients/sqs.d.ts to the following, you can import SQS.

// export = SQS;
export default SQS;

// in your file
import SQS from 'aws-sdk/clients/sqs';

Solution: 

However, at the moment, this is a preferred method for me by using require instead of import
const SQS = require('aws-sdk/clients/sqs');

Auth.currentCredentials()
  .then(credentials => {
    const sqs = new SQS({
      apiVersion: '2013-04-01',
      credentials: Auth.essentialCredentials(credentials)
    });

    // more code working with route53 object
    // route53.changeResourceRecordSets();
  })
source: https://github.com/ethereum/web3.js/issues/1491

For more information, you can check out the following StackOverflow threads for some discussion about require vs import.
1) Typescript import/as vs import/require? 
2) New es6 syntax for importing commonjs / amd modules i.e. `import foo = require('foo')`

Thanks for reading!

Jun