aws-sdk use only needed package e.g. couldwatchlog and config (with credentials)

Viewed 135

I want to use the cloudwatchlog client from AWS SDK (JS) and also set the credentials. So that I am not including the whole AWS SDK bundle inside my Application, because it is very large and slows down the page. Is there a way to configure the credentials and then only use the needed client from the AWS SDK?

so far I have tried this but it doesn't work with the config, typescript says the update method doesn't exist on Config:

import {Config} from 'aws-sdk/lib/core'; 
import {CloudWatchLogs} from 'aws-sdk';
1 Answers

Luckily I have just done this the other day to shrink down my bundle size as well. First I would recommend getting the correct aws-sdk config library with:

let Config = require('aws-sdk/global');

To get just the individual CloudWatchLogs you would need to get it like so:

let CloudWatchLogs = require('aws-sdk/clients/cloudwatchlogs');

After this you can configure the credentials like you would before, and to get a new CloudWatchLog you can do: let cloudwatch = new CloudWatchLogs()

Hopefully this helps some.

Related