diff --git a/package.json b/package.json index bc1f81e2..512948c3 100644 --- a/package.json +++ b/package.json @@ -21,10 +21,12 @@ }, "license": "Apache-2.0", "dependencies": { - "@architect/asap": "~6.0.4", + "@architect/asap": "~6.1.0-RC.0", "@architect/parser": "~6.0.3", - "@architect/utils": "~3.1.9", - "lambda-runtimes": "~1.1.6" + "@architect/utils": "~4.0.0-RC.1", + "@aws-lite/client": "~0.12.2", + "@aws-lite/ssm": "~0.2.1", + "lambda-runtimes": "~1.1.7" }, "devDependencies": { "@architect/eslint-config": "~2.1.2", @@ -35,6 +37,7 @@ "eslint": "~8.55.0", "mock-tmp": "~0.0.2", "nyc": "~15.1.0", + "proxyquire": "~2.1.3", "tap-arc": "^1.2.2", "tape": "^5.7.2" }, diff --git a/src/env/index.js b/src/env/index.js index 4ace41f6..4c9d2fc8 100644 --- a/src/env/index.js +++ b/src/env/index.js @@ -8,68 +8,40 @@ module.exports = function env (params, inventory, callback) { return callback() } - /* istanbul ignore next */ - try { - // eslint-disable-next-line - try { require('aws-sdk/lib/maintenance_mode_message').suppress = true } - catch { /* Noop */ } - // eslint-disable-next-line - var aws = require('aws-sdk') - } - catch (err) { - let msg = `'aws-sdk' not found, please install locally or globally (see also readme#aws-sdk-caveat)` - return callback(Error(msg)) - } + let aws let name = inventory.app let { region } = inventory.aws - let ssm = new aws.SSM({ region }) let result = [] + // eslint-disable-next-line + let awsLite = require('@aws-lite/client') + /* istanbul ignore next */ + awsLite({ region }).then(_aws => { + aws = _aws - function getSomeEnvVars (name, NextToken, callback) { - // Base query to ssm - let query = { + // Perform the query + let params = { Path: `/${name}`, Recursive: true, MaxResults: 10, - WithDecryption: true + WithDecryption: true, + paginate: true } - - // Check if we're paginating - /* istanbul ignore if */ - if (NextToken) query.NextToken = NextToken - - // Perform the query - ssm.getParametersByPath(query, function _query (err, data) { - if (err) callback(err) - else { - // Tidy up the response - result = result.concat(data.Parameters.map(function (param) { - let bits = param.Name.split('/') - return { - app: name, // jic - env: bits[2], - name: bits[3], - value: param.Value, - } - })) - // Check for more data and, if so, recurse - /* istanbul ignore if: Sadly no way to easily mock this for testing */ - if (data.NextToken) { - getSomeEnvVars(name, data.NextToken, callback) + aws.ssm.GetParametersByPath(params).then(data => { + // Tidy up the response + result = result.concat(data.Parameters.map(param => { + let bits = param.Name.split('/') + return { + app: name, // jic + env: bits[2], + name: bits[3], + value: param.Value, } - else callback(null, result) - } - }) - } + })) - getSomeEnvVars(name, false, function done (err, result) { - if (err) callback(err) - else { let testing = null let staging = null let production = null if (result.length) { - // TODO refactor into a reducer? result.forEach(({ env, name: k, value: v }) => { if (env === 'testing') testing = Object.assign({}, testing, { [k]: v }) if (env === 'staging') staging = Object.assign({}, staging, { [k]: v }) @@ -85,10 +57,9 @@ module.exports = function env (params, inventory, callback) { errors, }) if (errors.length) { - callback(Error(errors[0])) - return + return callback(Error(errors[0])) } callback() - } - }) + }).catch(err => callback(err)) + }).catch(err => callback(err)) } diff --git a/test/integration/function-config-test.js b/test/integration/function-config-test.js index 5c39f809..e28d369b 100644 --- a/test/integration/function-config-test.js +++ b/test/integration/function-config-test.js @@ -71,7 +71,7 @@ test('[Global runtime alias] Inventory and compare functions with / without func t.ok(get, 'Inventory returned getter') let def = inv._project.defaultFunctionConfig let custom = { - runtime: 'nodejs14.x', + runtime: 'nodejs18.x', runtimeAlias: undefined, architecture: 'arm64', timeout: 10, diff --git a/test/mock/function-config/global-alias/src/http/get-config/config.arc b/test/mock/function-config/global-alias/src/http/get-config/config.arc index 584a6399..51418993 100644 --- a/test/mock/function-config/global-alias/src/http/get-config/config.arc +++ b/test/mock/function-config/global-alias/src/http/get-config/config.arc @@ -1,6 +1,6 @@ # Non-defaults all around @aws -runtime nodejs14.x +runtime nodejs18.x timeout 10 memory 128 storage 1337 diff --git a/test/unit/src/config/pragmas/populate-lambda/get-runtimes-test.js b/test/unit/src/config/pragmas/populate-lambda/get-runtimes-test.js index 6d041739..e7b8dd34 100644 --- a/test/unit/src/config/pragmas/populate-lambda/get-runtimes-test.js +++ b/test/unit/src/config/pragmas/populate-lambda/get-runtimes-test.js @@ -23,7 +23,7 @@ test('Friendly runtime names (aka aliases)', t => { t.equal(config.runtimeAlias, 'python', `Alias returned lowcase as runtimeAlias: ${config.runtimeAlias}`) config = getRuntimes({ config: c('ruby'), inventory }) - t.match(config.runtime, /ruby2\.\d/, `Alias mapped to valid AWS Ruby string: ${config.runtime}`) + t.match(config.runtime, /ruby3\.\d/, `Alias mapped to valid AWS Ruby string: ${config.runtime}`) t.equal(config.runtimeAlias, 'ruby', `Alias returned lowcase as runtimeAlias: ${config.runtimeAlias}`) config = getRuntimes({ config: c('java'), inventory }) diff --git a/test/unit/src/config/project/index-test.js b/test/unit/src/config/project/index-test.js index f5f85512..1f56c5a6 100644 --- a/test/unit/src/config/project/index-test.js +++ b/test/unit/src/config/project/index-test.js @@ -136,7 +136,7 @@ test('Project plugins', t => { // Env + custom runtime plugins let env = { henlo: 'friend' } - let runtime = { name: 'typescript', type: 'transpiled', build: 'dist', baseRuntime: 'nodejs14.x' } + let runtime = { name: 'typescript', type: 'transpiled', build: 'dist', baseRuntime: 'nodejs20.x' } let plugins = { _methods: { set: { env: [ () => (env) ], runtimes: [ () => (runtime) ], diff --git a/test/unit/src/config/project/plugins/runtimes-test.js b/test/unit/src/config/project/plugins/runtimes-test.js index 105df76b..1edd1877 100644 --- a/test/unit/src/config/project/plugins/runtimes-test.js +++ b/test/unit/src/config/project/plugins/runtimes-test.js @@ -82,7 +82,7 @@ test('Transpiled runtime setters', t => { let inventory, plugin, plugins, runtime let type = 'transpiled' let build = '.build' // Just make sure it's different from the default 'build' - let baseRuntime = 'nodejs14.x' + let baseRuntime = 'nodejs20.x' let errors = [] // Transpiled with default build dir @@ -166,7 +166,7 @@ test('Runtime setter validation', t => { t.plan(16) let errors, inventory, plugin, runtime let type = 'transpiled' - let baseRuntime = 'nodejs14.x' + let baseRuntime = 'nodejs20.x' // No name runtime = { type } @@ -205,13 +205,13 @@ test('Runtime setter validation', t => { t.match(errors[0], /Runtime plugin must provide a valid type/, 'Returned correct type error') // Name cannot conflict with an existing runtime - runtime = { name: 'nodejs14.x', type } + runtime = { name: 'nodejs20.x', type } plugin = () => runtime inventory = newInv([ plugin ]) errors = [] setRuntimesPlugins({ inventory, errors }, emptyProj) t.equal(errors.length, 1, 'Returned an error') - t.match(errors[0], /Runtime name 'nodejs14\.x' is reserved/, 'Returned correct name error') + t.match(errors[0], /Runtime name 'nodejs20\.x' is reserved/, 'Returned correct name error') // Name cannot conflict with an existing custom runtime runtime = { name, type, baseRuntime } diff --git a/test/unit/src/env/index-test.js b/test/unit/src/env/index-test.js index ce9cf583..4bd7aaea 100644 --- a/test/unit/src/env/index-test.js +++ b/test/unit/src/env/index-test.js @@ -1,10 +1,20 @@ let { join } = require('path') let test = require('tape') +let proxyquire = require('proxyquire') + +async function awsLite () { + return { ssm: { + GetParametersByPath: async () => { + if (response instanceof Error) throw response + return response + } + } } +} + let sut = join(process.cwd(), 'src', 'env') -let getEnv = require(sut) -let awsMock = require('aws-sdk-mock') -let aws = require('aws-sdk') -awsMock.setSDKInstance(aws) +let getEnv = proxyquire(sut, { + '@aws-lite/client': awsLite +}) let app = 'an-app' let nulls = { @@ -41,10 +51,6 @@ let reset = () => { test('Set up env', t => { t.plan(1) t.ok(getEnv, 'Env var getter is present') - awsMock.mock('SSM', 'getParametersByPath', function (p, callback) { - if (response instanceof Error) callback(response) - else callback(null, response) - }) }) test('Do nothing', t => { @@ -261,6 +267,5 @@ test('Error handling', t => { test('Teardown', t => { t.plan(1) - awsMock.restore() t.pass('All done') }) diff --git a/test/unit/src/validate/config-test.js b/test/unit/src/validate/config-test.js index 098d70a5..c8c20978 100644 --- a/test/unit/src/validate/config-test.js +++ b/test/unit/src/validate/config-test.js @@ -15,7 +15,7 @@ let reset = () => { } let name = 'an-event' -let okRuntime = 'nodejs14.x' +let okRuntime = 'nodejs20.x' let okMemory = 1000 let okTimeout = 30 let okStorage = 1024 diff --git a/test/unit/src/validate/index-test.js b/test/unit/src/validate/index-test.js index ee47ca9b..52d57606 100644 --- a/test/unit/src/validate/index-test.js +++ b/test/unit/src/validate/index-test.js @@ -80,7 +80,7 @@ test('Configuration errors', t => { test('Table validation errors', t => { t.plan(1) let tables = [ { name: 'table' } ] - let streams = [ { name: 'foo', table: 'foo', config: { runtime: 'nodejs14.x', ...config } } ] + let streams = [ { name: 'foo', table: 'foo', config: { runtime: 'nodejs20.x', ...config } } ] let inventory = { ...defaults, tables, 'tables-streams': streams } let err = finalValidation(params, inventory) if (!err) t.fail('Expected an error')