Using Cognito JavaScript SDK without AWS-SDK - javascript

I'm using the Amazon's JavaScript AWS-SDK to set the region and credentials for me to use Cognito on my client application. The problem is that the AWS-SDK is huge! Is there a way to import only what I need or not importing anything from the AWS-SDK at all?
Here is my code:
import AWS from 'aws-sdk/global'
AWS.config.region = region
AWS.config.credentials = new AWS.CognitoIdentityCredentials({
IdentityPoolId: IdentityPoolId
})

From the Cognito SDK docs:
The Amazon Cognito Identity SDK for JavaScript depends on:
The CognitoIdentityServiceProvider service from the AWS SDK for
JavaScript
So you can't use it without the regular AWS SDK for JavaScript. However on that same page it tells you how to create a slimmed down version of the AWS SDK that only includes the needed Cognito dependencies. It also provides a direct link to a slimmed down version ready to use (but with a different namespace). I would recommend going here to download a custom version of the SDK that only includes the pieces you need.

There are specialized versions of the AWS SDK just for Cognito and you can build the AWS SDK just for the services that you require.
Here is an example just for Cognito:
Cognito Identity SDK
Here is the link to build your own custom AWS SDK:
AWS SDK for JavaScript in the Browser
I recommend customizing the official JavaScript SDK and not using specialized versions as the APIs and use cases can be different or limited in functionality.
There is a third option which is to not use the AWS SDKs at all and code everything by hand. This is definitely for experts as you have to deal directly with the REST API, creating signatures, etc.
A Google search will turn up lots of variants of the Cognito SDK.

Related

how to create Domain Identity in aws SES using javascipt sdk

I installed following package (AWS SDK for JavaScript v3) , not the entire pacakge only SES module as described in here
https://docs.aws.amazon.com/AWSJavaScriptSDK/v3/latest/clients/client-ses/index.html
my goal is to create Domain Identity using api.
I can't find the correct command to achieve my goal. I assume all available commands are listed here
https://docs.aws.amazon.com/AWSJavaScriptSDK/v3/latest/clients/client-ses/globals.html
is it something impossible to do with this version of sdk ?

How to create a backend to hide API keys in Reactjs app?

I am currently developing an app using Reactjs. I had hidden my API keys and AWS keys in the dotenv file. But I just realized that this was absolutely not secured. My current set up is that my app is running in an S3 bucket on AWS, and I was wondering if I could use my EC2 instance to hide my keys from users, but still being able to get them in the app.
This is the first time I am developing an app in Reactjs and I don't really know where to start.
Have a look at AWS Amplify, it makes that process super easy.
Using React & AWS Amplify, you can create a serverless architecture for this type of setup with minimal work. You can get started by following the instructions at https://aws-amplify.github.io/docs/
In a nutshel :
Install with:
npm install -g #aws-amplify/cli
$ amplify configure
Then in your project :
amplify init
amplify add api #this will create your API as AWS Lambda functions exposed through Amazon API Gateway)
amplify push #to create all this on your AWS account for you
If you search for 'aws amplify react' you will easily find a dozen blog posting showing you how to get started. There are so many I can not recommend one in particular.

The difference between AWS Amplify and amazon-cognito-identity-js?

I'm reviewing this demo of how to integrate Cognito with Angular, and it amazon-cognito-identity-js for the authorization service.
It seems that is what we should be using, but other tutorials install AWS Amplify as a whole:
npm i aws-amplify
Curious what the difference is and whether one is more current than the other?
amazon-cognito-identity-js used to be a separate package specifically for Cognito. Recently they've been bundling all their SDKs into Amplify to streamline the integration process.
For instance in our iOS app the Cognito SDK had a number of issues that were resolved by moving to Amplify.
As you can see in the link below, this package is now maintained in the Amplify umbrella.
https://github.com/aws-amplify/amplify-js/tree/master/packages/amazon-cognito-identity-js
It used to be standalone here:
https://github.com/amazon-archives/amazon-cognito-identity-js
I would recommend going forward with Amplify as that is the direction that AWS development is headed internally, and amazon-cognito-identity-js is maintained as part of Amplify anyway.
To add to the great answer by #DaveS. There are 3 official tools you can use to integrate Cognito in your app:
Amplify
Use it in client-side applications, where you'd use Amplify anyway - to leverage the premade auth UI components or to integrate with other services from the Amplify ecosystem: APIs, Analytics, Storage, etc.
Does not support secret-enabled Cognito app clients.
Cannot make authenticated (requiring AWS credentials) Cognito API calls (e.g. adminCreateUser) directly, but there's a workaround.
amazon-cognito-identity-js
It is a much smaller package and it comes as a part of Amplify (hosted in the Amplify monorepo).
It can still be used separately if you don't need any of the extra features provided by Amplify (save on the bundle size).
Does not support secret-enabled Cognito app clients.
Cannot make authenticated (requiring AWS credentials) Cognito API calls, e.g. adminCreateUser.
Can be used in the backend (unauthenticated Cognito APIs only).
AWS SDK
Low-level as it can get.
Provides access to all (authenticated and non-authenticated) Cognito APIs. For authenticated, make sure the code has access to AWS credentials.
Can work with secret-enabled Cognito client apps (you need to sign the requests with the secret).
Can be used in both client (for unauthenticated APIs only, otherwise you're exposing secrets) and server applications.
Code samples for all 3 can be found here: AWS Cognito: Amplify vs amazon-cognito-identity-js vs AWS SDK.

API Gateway Javascript SDK - Node Js Examples?

So The API Gateway Javascript SDK is great to use in the front-end environment, but since the 10+ script files are required to be available globally, this does not play very nicely in an environment where most developers are used to importing npm packages.
Is there an example of anyone using the API Gateway SDK in backend Node.js environment? Here you cannot put the 10+ scripts in index.html file and I keep getting errors and when I try to make these files globally available for the SDK in Node environment.
There are two AWS SDKs for JavaScript. Use the one for node.js linked in the comment from MaiKaY. And here is the reference for the API Gateway portion of the SDK - http://docs.aws.amazon.com/AWSJavaScriptSDK/latest/AWS/APIGateway.html

Initialization in node.js || How to handle initial configuration in node.js

I recently transited from Java to JavaScript specifically MEAN Stack Development. I want to make API in node.js such that it initializes all configuration upon deployment like init method in Servlets.
If there is any other standardized way to accomplish this task kindly guide me.
You have to go with Loopback is a highly-extensible, open-source Node.js API framework.
Features
Quickly create dynamic end-to-end REST APIs.
Connect devices and browsers to data and services.
Use Android, iOS, and AngularJS SDKs to easily create client apps.
Add-on components for push, file management, 3rd-party login, and geolocation.
Use StrongLoop Arc to visually edit, deploy, and monitor LoopBack apps.
StrongLoop API Gateway acts an intermediary between API consumers (clients) and API providers to externalize, secure, and manage
APIs.
Runs on-premises or in the cloud
How to install - To install this, simply run the following given command.
$ npm install -g strongloop
Hope this will help to resolve your query !!
You could look at Swagger which provides many tools for configuring, representing and validating a RESTful API.
There is a swagger-node module which, after defining your JSON API schema, can automatically configure your API for you.

Categories

Resources