From 1912ae1b90de73de31d924f8c14de5892cece8cc Mon Sep 17 00:00:00 2001 From: Steven Tsang Date: Thu, 12 Sep 2024 16:32:24 +0100 Subject: [PATCH] feat(nestjs-storage): Support IAM AWS S3 Credentials --- libs/nestjs-storage/src/storage.module.ts | 9 +++++---- 1 file changed, 5 insertions(+), 4 deletions(-) diff --git a/libs/nestjs-storage/src/storage.module.ts b/libs/nestjs-storage/src/storage.module.ts index f183b43c..214ee715 100644 --- a/libs/nestjs-storage/src/storage.module.ts +++ b/libs/nestjs-storage/src/storage.module.ts @@ -12,12 +12,13 @@ import { StorageService } from './services/storage.service' provide: S3Client, inject: [ConfigService], useFactory: (config: ConfigService) => { + const accessKeyId = config.get('AWS_ACCESS_KEY_ID') + const secretAccessKey = config.get('AWS_SECRET_ACCESS_KEY') + const credentials = accessKeyId && secretAccessKey ? { accessKeyId, secretAccessKey } : null + return new S3Client({ region: config.get('AWS_REGION', 'eu-west-2'), - credentials: { - accessKeyId: config.get('AWS_ACCESS_KEY_ID', ''), - secretAccessKey: config.get('AWS_SECRET_ACCESS_KEY', '') - } + credentials, }) } },