Ecosyste.ms: Awesome
An open API service indexing awesome lists of open source software.
https://github.com/asomethings/nest-aws
AWS Module for Nestjs framework
https://github.com/asomethings/nest-aws
aws nestjs
Last synced: 3 months ago
JSON representation
AWS Module for Nestjs framework
- Host: GitHub
- URL: https://github.com/asomethings/nest-aws
- Owner: asomethings
- License: mit
- Created: 2020-07-12T07:25:54.000Z (over 4 years ago)
- Default Branch: master
- Last Pushed: 2023-01-24T03:27:57.000Z (about 2 years ago)
- Last Synced: 2024-10-11T23:19:45.682Z (4 months ago)
- Topics: aws, nestjs
- Language: TypeScript
- Homepage:
- Size: 1.87 MB
- Stars: 2
- Watchers: 2
- Forks: 0
- Open Issues: 15
-
Metadata Files:
- Readme: README.md
- License: LICENSE.md
Awesome Lists containing this project
README
## Description
**Alpha Release: Use it with caution**
AWS Module for Nest.js framework
## Installation
NPM
```
npm i --save nest-aws
```Yarn
```
yarn add nest-aws
```## Usage
Import AwsModule into root AwsModule
```typescript
@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
```typescript
import { S3, SES } from 'aws-sdk'@Module({
imports: [
AwsModule.forFeature(S3, SES),
],
providers: [...],
})
export class AppModule {}
```Now, inject S3 and SES with InjectAwsService
```typescript
@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`
## Options
```typescript
AwsModule.forRoot({
// AWS Region (Optional)
region: '',// AWS Access Key Id (Optional)
accessKeyId: '...',// AWS Secret Access Key Id (Optional)
secretAccessKeyId: '...',
}),
```## Async Options
1. Use factory
```typescript
AwsModule.forRootAsync({
useFactory: () => ({
region: 'ap-northeast-2',
}),
})
```OR
```typescript
AwsModule.forRootAsync({
imports: [ConfigModule],
useFactory: (configService: ConfigService) => ({
accessKeyId: configService.get('accessKeyId'),
secretAccessKeyId: configService.get('secretAccessKeyId'),
}),
inject: [ConfigService],
})
```2. Use Class
```typescript
AwsModule.forRootAsync({
useClass: AwsConfigService
})
``````typescript
class AwsConfigService implements AwsOptionsFactory {
createAwsOptions(): Promise | AwsModuleOptions {
return {
region: 'ap-northeast-2',
}
}
}
```3. Use existing
```typescript
AwsModule.forRootAsync({
imports: [ConfigModule],
useExisting: ConfigService,
})```
## TODO
- [ ] Write Tests
- [ ] Support More Options
- [ ] Seperate AwsModule with AwsCoreModule (Like @nestjs/typeorm)