diff --git a/README.md b/README.md index ef187f2..7697d34 100644 --- a/README.md +++ b/README.md @@ -75,7 +75,6 @@ import LambdaEnvVars from 'lambda-env-vars'; const lambdaEnvVars = new LambdaEnvVars({ location: 's3', s3Config: { - region: 'eu-west-2', bucketName: 'my-env-var-bucket', fileName: 'my-env-var-filename.json', }, @@ -107,7 +106,6 @@ Optionally the source of environment variables can be a JSON file within an S3 b location: 's3', s3Config: { bucketName: 'name-of-bucket', - bucketRegion 'eu-west-2', fileName: 'filename.json', // Name of the JSON file containing the env vars }, } @@ -120,7 +118,6 @@ The available attributes of the params object are as follows: | location | string | 'lambdaConfig' | Can be 'lambdaConfig' or 's3'. The location the environment variables are stored. | s3Config | object | {} | Required when location is equal to 's3'. Fields that specify the location of the env var JSON file | | s3Config.bucketName | string | | The name of the bucket containing the env var file. | -| s3Config.bucketRegion | string | | The region of the bucket. | | s3Config.fileName | string | | The file name of the env var JSON file. | diff --git a/src/index.js b/src/index.js index 2b55846..27af57c 100644 --- a/src/index.js +++ b/src/index.js @@ -18,7 +18,6 @@ export default class LambdaEnvVars { * Config used to get the an env var file from S3. * * @param {string} params.s3Config.bucketName - * @param {string} params.s3Config.bucketRegion * @param {string} params.s3Config.fileName * * @return {Object} @@ -72,7 +71,6 @@ export default class LambdaEnvVars { * Config used to get the an env var file from S3. * * @param {string} params.s3Config.bucketName - * @param {string} params.s3Config.bucketRegion * @param {string} params.s3Config.fileName * * @return {Promise} @@ -83,7 +81,7 @@ export default class LambdaEnvVars { return this.buildParams(params) .then((builtParams) => { if (builtParams.location === 's3') { - return this.getVarFromS3File(variableName, params.s3Config); + return this.getVarFromS3File(variableName, builtParams.s3Config); } if (this.decryptedVariables[variableName]) { @@ -112,14 +110,13 @@ export default class LambdaEnvVars { * Promise that resolves the variable name */ getVarFromS3File(variableName, s3Config) { - const fileKey = s3Config.bucketRegion + s3Config.bucketName + s3Config.fileName; + const fileKey = s3Config.bucketName + s3Config.fileName; if (this.s3Vars[fileKey]) { return Promise.resolve(this.s3Vars[fileKey][variableName]); } const s3Params = { - region: s3Config.bucketRegion, Key: s3Config.fileName, Bucket: s3Config.bucketName, }; @@ -163,11 +160,10 @@ export default class LambdaEnvVars { ( !params.s3Config || !params.s3Config.bucketName || - !params.s3Config.bucketRegion || !params.s3Config.fileName ) ) { - const errorMessage = 's3Config.bucketName, s3Config.bucketRegion, s3Config.fileName are required when location is \'s3\''; + const errorMessage = 's3Config.bucketName and s3Config.fileName are required when location is \'s3\''; return Promise.reject(new Error(errorMessage)); } diff --git a/test/index.js b/test/index.js index 77a98aa..9dd25b3 100644 --- a/test/index.js +++ b/test/index.js @@ -99,14 +99,12 @@ test('Getting custom vars, uses s3 when the location is specified', (t) => { const params = { location: 's3', s3Config: { - bucketRegion: 'eu-west-1', bucketName: 'bucketName', fileName: 'file-name-4.json', }, }; - const storedVarKey = params.s3Config.bucketRegion + params.s3Config.bucketName + - params.s3Config.fileName; + const storedVarKey = params.s3Config.bucketName + params.s3Config.fileName; lambdaEnvVars.s3Vars[storedVarKey] = { variableName: 'value' }; @@ -186,22 +184,6 @@ test('Building request params: Rejects when s3Config is missing bucketName', (t) const params = { location: 's3', s3Config: { - bucketRegion: 'bucketRegion', - fileName: 'fileName', - }, - }; - - return lambdaEnvVars.buildParams(params) - .catch((error) => { - t.is(typeof error.message, 'string'); - }); -}); - -test('Building request params: Rejects when s3Config is missing bucketRegion', (t) => { - const params = { - location: 's3', - s3Config: { - bucketName: 'bucketName', fileName: 'fileName', }, }; @@ -217,7 +199,6 @@ test('Building request params: Rejects when s3Config is missing fileName', (t) = location: 's3', s3Config: { bucketName: 'bucketName', - bucketRegion: 'bucketRegion', }, }; @@ -232,7 +213,6 @@ test('Building request params: Resolves the params object', (t) => { location: 's3', s3Config: { bucketName: 'bucketName', - bucketRegion: 'bucketRegion', fileName: 'fileName', }, }; @@ -255,13 +235,11 @@ test( 'Getting var from s3 file: Resolves undefined when the file is stored but variable is undefined', (t) => { const defaultS3Config = { - bucketRegion: 'eu-west-1', fileName: 'file-name-1.json', bucketName: 'bucketName', }; - const storedVarKey = defaultS3Config.bucketRegion + defaultS3Config.bucketName + - defaultS3Config.fileName; + const storedVarKey = defaultS3Config.bucketName + defaultS3Config.fileName; lambdaEnvVars.s3Vars[storedVarKey] = {}; @@ -274,13 +252,11 @@ test( test('Getting var from s3 file: Resolves var when the file is stored', (t) => { const defaultS3Config = { - bucketRegion: 'eu-west-1', bucketName: 'bucketName', fileName: 'file-name-2.json', }; - const storedVarKey = defaultS3Config.bucketRegion + defaultS3Config.bucketName + - defaultS3Config.fileName; + const storedVarKey = defaultS3Config.bucketName + defaultS3Config.fileName; lambdaEnvVars.s3Vars[storedVarKey] = { variableName: 'value' }; @@ -292,7 +268,6 @@ test('Getting var from s3 file: Resolves var when the file is stored', (t) => { test('Getting var from s3 file: Rejects when the s3 file is not valid json', (t) => { const defaultS3Config = { - bucketRegion: 'eu-west-1', fileName: 'invalid-json.json', bucketName: 'bucketName', }; @@ -305,7 +280,6 @@ test('Getting var from s3 file: Rejects when the s3 file is not valid json', (t) test('Getting var from s3 file: Resolves the file once fetched from S3', (t) => { const defaultS3Config = { - bucketRegion: 'eu-west-1', fileName: 'file-name-3.json', bucketName: 'bucketName', };