Alpha Release: Use it with caution
AWS Module for Nest.js framework
NPM
npm i --save nest-aws
Yarn
yarn add nest-aws
Import AwsModule into root AwsModule
@Module({
imports: [
AwsModule.forRoot({
region: 'ap-northeast-2'
accessKeyId: 'your-aws-access-key',
secretAccessKeyId: 'your-aws-secret-key',
}),
],
providers: [...],
})
export class AppModule {}
Define AWS Services that you wan't to use
import { S3, SES } from 'aws-sdk'
@Module({
imports: [
AwsModule.forFeature(S3, SES),
],
providers: [...],
})
export class AppModule {}
Now, inject S3 and SES with InjectAwsService
@Injectable()
export class UserService {
constructor(
@InjectAwsService(S3)
private readonly s3: S3,
@InjectAwsService(SES)
private readonly ses: SES,
) {}
}
All AWS Services will be initiated with settings that you have provided in forRoot
AwsModule.forRoot({
// AWS Region (Optional)
region: '',
// AWS Access Key Id (Optional)
accessKeyId: '...',
// AWS Secret Access Key Id (Optional)
secretAccessKeyId: '...',
}),
AwsModule.forRootAsync({
useFactory: () => ({
region: 'ap-northeast-2',
}),
})
OR
AwsModule.forRootAsync({
imports: [ConfigModule],
useFactory: (configService: ConfigService) => ({
accessKeyId: configService.get('accessKeyId'),
secretAccessKeyId: configService.get('secretAccessKeyId'),
}),
inject: [ConfigService],
})
AwsModule.forRootAsync({
useClass: AwsConfigService
})
class AwsConfigService implements AwsOptionsFactory {
createAwsOptions(): Promise<AwsModuleOptions> | AwsModuleOptions {
return {
region: 'ap-northeast-2',
}
}
}
AwsModule.forRootAsync({
imports: [ConfigModule],
useExisting: ConfigService,
})