deligenius / aws-sdk-v3-nest

AWS SDK V3 dynamic module for NestJS
MIT License
40 stars 5 forks source link

Unable to use more than one feature clients #4

Closed ByBogon closed 1 year ago

ByBogon commented 1 year ago

Hi, I'm trying to use more than one clients such as sqs, dynamo, etc is there some way to use it? Just like nest-aws-sdk library has AwsSdkModule.forFeatures.

import { Module } from '@nestjs/common';
import { S3 } from 'aws-sdk';
import { AwsSdkModule } from 'nest-aws-sdk';

@Module({
  imports: [AwsSdkModule.forFeatures([S3])],
  providers: [],
  exports: [],
})
class AppSubModule {}
gjuoun commented 1 year ago

Hi you post the issue to a wrong git repo.
you are using nest-aws-sdk and it's not aws-sdk-v3-nest

ByBogon commented 1 year ago

Hi I meant that is an example of some different repo that is able to use multiple client. I just found this repo also can use multiple clients by doc

Multiple Injection/Instances

Please use key attribute as the identifier for each Client

Example:

  1. register the S3 Client with a unique key

    AwsSdkModule.register({
    // register the S3 Client with key `US-WEST-2-CLIENT`
    key: 'US-WEST-2-CLIENT',
    client: new S3Client({
    region: 'us-west-2',
    }),
    }),
    AwsSdkModule.register({
    // register the S3 Client with key `US-EAST-1-CLIENT`
    key: 'US-EAST-1-CLIENT',
    client: new S3Client({
    region: 'us-east-1',
    }),
    }),
  2. refer the S3 client use @InjectAws(Client, key)

    @InjectAws(S3Client, "US-WEST-2-CLIENT") private readonly s3west2: S3Client,
    @InjectAws(S3Client, "US-EAST-1-CLIENT") private readonly s3east1: S3Client,

Thanks.

gjuoun commented 1 year ago

Sorry for misunderstood. Yes, you can use key as identifiers for instances.

ByBogon commented 1 year ago

No problem! Really appreciate it for your library.

And do I have to set the key for different type of clients? Like with sqs client and dynamodb client

Because the above example seems like it's only for same clients but different configurations (ex: region)