diff --git a/package.json b/package.json index 2679565..c6ca8b1 100644 --- a/package.json +++ b/package.json @@ -1,6 +1,6 @@ { "name": "@mhlabs/lambda-local", - "version": "1.1.1", + "version": "2.0.0", "description": "A package for mapping AWS env to local env", "main": "index.js", "jest": { diff --git a/src/lambdaEnvironment.js b/src/lambdaEnvironment.js index 81ef2e1..036bf8a 100644 --- a/src/lambdaEnvironment.js +++ b/src/lambdaEnvironment.js @@ -1,23 +1,25 @@ const aws = require('aws-sdk'); const ssoAuth = require('@mhlabs/aws-sso-client-auth'); -async function mapToLocal( - stackName, - region = 'eu-west-1', - apiProxyLogicalId = 'ApiProxy', - ssoStartUrl = null, - ssoAccountId = null, - ssoRole = null -) { +async function mapToLocal(settings) { + const { + region = 'eu-west-1', + apiProxyLogicalId = 'ApiProxy', + stackName = null, + ssoStartUrl = null, + ssoAccountId = null, + ssoRole = null + } = settings; + process.env.AWS_DEFAULT_REGION = region; process.env.AWS_REGION = region; if (ssoStartUrl) { await ssoAuth.configure({ - clientName: 'evb-cli', + clientName: stackName, startUrl: ssoStartUrl, accountId: ssoAccountId, - region: region + region }); aws.config.update({ diff --git a/src/lambdaEnvironment.test.js b/src/lambdaEnvironment.test.js index 8fbe578..4ccf50a 100644 --- a/src/lambdaEnvironment.test.js +++ b/src/lambdaEnvironment.test.js @@ -1,7 +1,7 @@ const tested = require('./lambdaEnvironment'); test('Should map env variables', async () => { - await tested.mapToLocal('virtual-test-stack'); + await tested.mapToLocal({ stackName: 'virtual-test-stack' }); expect(process.env.AWS_REGION).toBe('eu-west-1'); expect(process.env.AWS_DEFAULT_REGION).toBe('eu-west-1'); expect(process.env.CODE_LIMIT).toBe('5');