BeerMoneyDev / nest-aws-sdk

A thin wrapping layer around the aws-sdk package for clean NestJS dependency injection.
MIT License
93 stars 13 forks source link

Issue with .forRootAsync #3

Open benMain opened 3 years ago

benMain commented 3 years ago

During module initialization, if I provide serviceProviders but not the optional defaultServiceOptions the code returns before adding my serviceProviders to the Providers and exports of the dynamic modules

benMain commented 3 years ago

@KerryRitter fix this!

felinto-dev commented 3 years ago

Try it

@Module({
  imports: [
    AwsSdkModule.forRootAsync({
      defaultServiceOptions: {
        inject: [ConfigService],
        useFactory: (configService) => ({
          credentials: {
            accessKeyId: configService.get('scaleway.ACCESS_KEY_ID'),
            secretAccessKey: configService.get('scaleway.SECRET_ACCESS_KEY'),
          },
          region: configService.get('scaleway.REGION'),
          endpoint: configService.get('scaleway.ENDPOINT'),
        }),
      },
      services: [S3],
    }),
  ],
})

PS: Double-check for import "configService" from "@nestjs/config"

(just an example config)

felinto-dev commented 3 years ago

After a lot of headaches with this plugin and others that propose to be a wrapper between nestjs and aws-sdk, I decided to configure the dependency injection by myself and the result was not bad.

https://gist.github.com/felinto-dev/0450a3484ddd8aefefc79f42797eeadf

KerryRitter commented 3 years ago

After a lot of headaches with this plugin and others that propose to be a wrapper between nestjs and aws-sdk, I decided to configure the dependency injection by myself and the result was not bad.

https://gist.github.com/felinto-dev/0450a3484ddd8aefefc79f42797eeadf

Sorry to hear you had problems. Are your issues related to what @benMain posted? Looks like you supply the default options.

That said, your solution is how I would approach the problem without nest-aws-sdk.

geekyayush commented 1 year ago

After a lot of headaches with this plugin and others that propose to be a wrapper between nestjs and aws-sdk, I decided to configure the dependency injection by myself and the result was not bad.

https://gist.github.com/felinto-dev/0450a3484ddd8aefefc79f42797eeadf

Thank you so much @felinto-dev for the code snippet. I have been facing some issues while using the library. I was getting the following error:

Potential solutions:
- If S3ManagerService is a provider, is it part of the current DocumentModule?
- If S3ManagerService is exported from a separate @Module, is that module imported within DocumentModule?
  @Module({
    imports: [ /* the Module containing S3ManagerService */ ]
  })

But now, using your method, worked for me.