{"id":25878249,"url":"https://github.com/deligenius/aws-sdk-v3-nest","last_synced_at":"2025-04-05T13:07:33.655Z","repository":{"id":61652691,"uuid":"553338636","full_name":"deligenius/aws-sdk-v3-nest","owner":"deligenius","description":"AWS SDK V3 dynamic module for NestJS","archived":false,"fork":false,"pushed_at":"2024-10-29T01:04:27.000Z","size":407,"stargazers_count":44,"open_issues_count":0,"forks_count":6,"subscribers_count":2,"default_branch":"main","last_synced_at":"2025-03-02T06:02:43.432Z","etag":null,"topics":["aws","aws-sdk-javascript","aws-sdk-v3","nestjs","typescript"],"latest_commit_sha":null,"homepage":"","language":"TypeScript","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"mit","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/deligenius.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":null,"license":"LICENSE","code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null,"governance":null,"roadmap":null,"authors":null,"dei":null,"publiccode":null,"codemeta":null}},"created_at":"2022-10-18T04:12:16.000Z","updated_at":"2025-02-01T14:34:59.000Z","dependencies_parsed_at":"2023-12-22T18:32:36.355Z","dependency_job_id":"7c1c1d49-c6fb-4579-9364-668f042ca3cd","html_url":"https://github.com/deligenius/aws-sdk-v3-nest","commit_stats":{"total_commits":18,"total_committers":1,"mean_commits":18.0,"dds":0.0,"last_synced_commit":"9fe1bc8e3384956269c587729a076af064dd5e86"},"previous_names":[],"tags_count":2,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/deligenius%2Faws-sdk-v3-nest","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/deligenius%2Faws-sdk-v3-nest/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/deligenius%2Faws-sdk-v3-nest/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/deligenius%2Faws-sdk-v3-nest/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/deligenius","download_url":"https://codeload.github.com/deligenius/aws-sdk-v3-nest/tar.gz/refs/heads/main","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":247339158,"owners_count":20923014,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2022-07-04T15:15:14.044Z","host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":["aws","aws-sdk-javascript","aws-sdk-v3","nestjs","typescript"],"created_at":"2025-03-02T12:23:07.293Z","updated_at":"2025-04-05T13:07:33.628Z","avatar_url":"https://github.com/deligenius.png","language":"TypeScript","funding_links":[],"categories":[],"sub_categories":[],"readme":"\n\n# AWS SDK V3 Nest \n\n\n\u003e AWS SDK Javascript V3 dynamic module for NestJS\n\n[![TypeScript](https://img.shields.io/badge/--3178C6?logo=typescript\u0026logoColor=ffffff)](https://www.typescriptlang.org/) \n[![Npm package version](https://badgen.net/npm/v/aws-sdk-v3-nest)](https://www.npmjs.com/package/aws-sdk-v3-nest)\n![npm](https://img.shields.io/npm/dw/aws-sdk-v3-nest)\n![NPM](https://img.shields.io/npm/l/aws-sdk-v3-nest)\n![GitHub Repo stars](https://img.shields.io/github/stars/deligenius/aws-sdk-v3-nest?style=social)\n\n\n\u003cdetails\u003e\n\n\u003csummary\u003e\u003ch3\u003eQuick Start\u003c/h3\u003e\u003c/summary\u003e\n\n\nLet's build a S3 client and inject it into the nest app.\n\n```\nnpm install aws-sdk-v3-nest @aws-sdk/client-s3\n```\n\n1. Register the module with a S3 Client, in `app.module.ts`\n\n```ts\nimport { Module } from '@nestjs/common';\nimport { AppController } from './app.controller';\nimport { AppService } from './app.service';\nimport { AwsSdkModule } from 'aws-sdk-v3-nest';\nimport { S3Client } from '@aws-sdk/client-s3';\n\n@Module({\n  imports: [\n    // register S3 client\n    AwsSdkModule.register({\n      client: new S3Client({\n        region: 'us-west-2',\n      }),\n    }),\n  ],\n  controllers: [AppController],\n  providers: [AppService],\n})\nexport class AppModule {}\n```\n\n2. use the S3 client in `app.controller.ts`\n\n```ts\nimport { ListBucketsCommand, S3Client } from '@aws-sdk/client-s3';\nimport { Controller, Get } from '@nestjs/common';\nimport { AppService } from './app.service';\nimport { InjectAws } from 'aws-sdk-v3-nest';\n\n@Controller()\nexport class AppController {\n  constructor(\n    private readonly appService: AppService,\n    // inject the client\n    @InjectAws(S3Client) private readonly s3: S3Client \n  ) {}\n  @Get()\n  async helloAws() {\n    const listCommand = new ListBucketsCommand({});\n    const res = await this.s3.send(listCommand);\n    return res;\n  }\n}\n```\n\n3. done!\n\n\u003c/details\u003e\n\n## Installation\n\n* Add `aws-sdk-v3-nest` to your project\n  ```bash\n   npm install aws-sdk-v3-nest\n   ```\n* Make sure at least one [AWS SDK for JavaScript V3](https://docs.aws.amazon.com/AWSJavaScriptSDK/v3/latest/index.html) is in your project. Please skip this step if you already have it installed\n  ```bash\n  npm install @aws-sdk/client-s3\n   ```\n\n## Add Environment Variables\n\nEnsure the following environment variables are present in your project. These variables are critical for authentication and communication with AWS services.\n\n**Security Note:** Treat these keys as sensitive information. Do not commit them to public repositories and ensure they are securely stored and accessed.\n\n**Setting Up:** Typically, these variables are placed in a `.env` file in your project's root directory or configured directly in your deployment platform's environment settings.\n\n```bash\nAWS_ACCESS_KEY_ID=your_access_key_id\nAWS_SECRET_ACCESS_KEY=your_secret_access_key\n```\n\n## Register a Client\n\nYou can register any AWS SDK client you want. As long as it's a [AWS SDK V3 client](https://docs.aws.amazon.com/AWSJavaScriptSDK/v3/latest/index.html)\n\nA good example: [`S3Client`](https://docs.aws.amazon.com/AWSJavaScriptSDK/v3/latest/client/s3/)\n\n\u003cimg width=\"324\" alt=\"image\" src=\"https://github.com/deligenius/aws-sdk-v3-nest/assets/8935612/10230c29-0ad3-4bf7-a07d-e0a0e866b166\"\u003e\n\n```ts\nimport { S3Client } from '@aws-sdk/client-s3';\nimport { AwsSdkModule } from 'aws-sdk-v3-nest';\n\n// ... your code ...\n\nAwsSdkModule.register({\n  client: new S3Client({\n    region: 'us-west-2',\n  }),\n});\n```\n\n\n\n\n## Async Register\n\nThe library provides an async `useFactory` that allows you to add more logics before setting up the client instance.\n\n```ts\nimport { S3Client, ListBucketsCommand } from '@aws-sdk/client-s3';\nimport { AwsSdkModule } from 'aws-sdk-v3-nest';\n\n//... your code ...\n\nAwsSdkModule.registerAsync({\n  clientType: S3Client,\n  useFactory: async () =\u003e {\n    const s3 = new S3Client({\n      region: 'us-west-2',\n    });\n\n    try {\n      const listCommand = new ListBucketsCommand({});\n      const res = await s3.send(listCommand);\n      console.log('Connected to S3');\n    } catch (e) {\n      console.log('Unable to connect to S3', e);\n    }\n\n    return s3;\n  },\n});\n```\n\n### Use `@InjectAws(Client)`\n\nWith a registered S3 client, you can now inject the instance to your service and controller.\n\n\u003e Make sure the `Client` is the type you registered in module.\n\n```ts\n/** Use S3 client in AppController */\nimport { ListBucketsCommand, S3Client } from '@aws-sdk/client-s3';\nimport { Controller, Get } from '@nestjs/common';\nimport { AppService } from './app.service';\nimport { InjectAws } from 'aws-sdk-v3-nest';\n\n@Controller()\nexport class AppController {\n  constructor(\n    private readonly appService: AppService,\n    @InjectAws(S3Client) private readonly s3: S3Client,\n  ) {}\n  @Get()\n  async helloAws() {\n    const listCommand = new ListBucketsCommand({});\n    const res = await this.s3.send(listCommand);\n    return res;\n  }\n}\n```\n\n## Multiple Injection/Instances\n\nTo add more instances is easy, just `register` more! \nIf you have same type of clients, please use the `key` attribute as the identifier.\n\nExample for multiple S3 client instances\n\n### Register the S3 Client with a unique `key`\n```ts\nAwsSdkModule.register({\n  // register the S3 Client with key `US-WEST-2-CLIENT`\n  key: 'US-WEST-2-CLIENT',\n  client: new S3Client({\n    region: 'us-west-2',\n  }),\n}),\nAwsSdkModule.register({\n  // register the S3 Client with key `US-EAST-1-CLIENT`\n  key: 'US-EAST-1-CLIENT',\n  client: new S3Client({\n    region: 'us-east-1',\n  }),\n}),\n```\n\n### Inject and refer clients by `@InjectAws(Client, key)`\n```ts\n@InjectAws(S3Client, \"US-WEST-2-CLIENT\") private readonly s3west2: S3Client,\n@InjectAws(S3Client, \"US-EAST-1-CLIENT\") private readonly s3east1: S3Client,\n```\n\n## Global Module\n\nBy default, a client is only available at where it is registered.\nYou have an option to make it global, `isGlobal: true`\n\n```ts\nAwsSdkModule.register({\n  isGlobal: true,\n  client: new S3Client({\n    region: 'us-west-2',\n  }),\n});\n```\n\n## Get client token\n\nIf you need a client key for testing purpose. Please pass the [AWS SDK V3 client](https://docs.aws.amazon.com/AWSJavaScriptSDK/v3/latest/index.html) and `key` to `getClientToken`\n\n```ts\ngetClientToken(S3Client, key = \"\")\n```\n\n### Credit\n\nInspired by: [nest-aws-sdk](https://www.npmjs.com/package/nest-aws-sdk)\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fdeligenius%2Faws-sdk-v3-nest","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fdeligenius%2Faws-sdk-v3-nest","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fdeligenius%2Faws-sdk-v3-nest/lists"}