Skip to content

Commit

Permalink
Move calls to new aws-lite endpoint param
Browse files Browse the repository at this point in the history
Update deps
Use `tap-arc`
  • Loading branch information
ryanblock committed Jan 29, 2024
1 parent 4bff97b commit 941d797
Show file tree
Hide file tree
Showing 7 changed files with 26 additions and 20 deletions.
2 changes: 1 addition & 1 deletion _changelog.md
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ Architect Functions just got a lot faster. Gone are the days of 500-1000ms cold
- If you only rely on the DocumentClient (`_doc`), you may want to just try using the new [`@aws-lite/dynamodb`](https://aws-lite.org/services/dynamodb)-based `_client`
- Breaking change: while we've taken efforts to ensure the maximum degree of compatibility with AWS SDK v2 and v3 errors, the errors returned in Arc Functions 8.0 (using `aws-lite`) may still vary slightly
- This only really applies if your error handling relies on specific properties or values
- If you just `console.log()` your errors, you will be totally fine, and the quality of the errors you get via `aws-lite` will mostly likely improve with this change
- If you just `console.log()` your errors, you will be totally fine, and the quality of the errors you get via `aws-lite` will most likely improve with this change
- Note: if you're an AWS SDK v2 user considering migrating to v3, error incompatibility will apply even more so; v3 errors are incompatible with v2, whereas `aws-lite` errors attempt to be compatible with both SDK v2 + v3
- Added Node.js 20.x to test matrix
- Breaking change: removed support for Node.js 14.x (now EOL, and no longer available to created in AWS Lambda)
Expand Down
19 changes: 9 additions & 10 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -12,8 +12,8 @@
"types": "types/index.d.ts",
"scripts": {
"lint": "eslint --fix .",
"test:unit": "cross-env tape 'test/unit/**/*-test.js' | tap-spec",
"test:integration": "cross-env tape 'test/integration/**/*-test.js' | tap-spec",
"test:unit": "cross-env tape 'test/unit/**/*-test.js' | tap-arc",
"test:integration": "cross-env tape 'test/integration/**/*-test.js' | tap-arc",
"coverage": "nyc --reporter=lcov --reporter=text npm run test:unit",
"test": "npm run lint && npm run test:integration && npm run coverage",
"test:types": "tsd --files types/*.test-d.ts",
Expand All @@ -26,8 +26,8 @@
"license": "Apache-2.0",
"dependencies": {
"@aws-lite/apigatewaymanagementapi": "^0.0.6",
"@aws-lite/client": "^0.13.1",
"@aws-lite/dynamodb": "^0.3.1",
"@aws-lite/client": "^0.15.0-RC.0",
"@aws-lite/dynamodb": "^0.3.3",
"@aws-lite/sns": "^0.0.4",
"@aws-lite/sqs": "^0.2.0",
"@aws-lite/ssm": "^0.2.2",
Expand All @@ -40,22 +40,21 @@
"uid-safe": "^2.1.5"
},
"devDependencies": {
"@architect/asap": "^6.0.4",
"@architect/asap": "^7.0.0-RC.1",
"@architect/eslint-config": "2.1.1",
"@architect/req-res-fixtures": "git+https://github.com/architect/req-res-fixtures.git",
"@architect/sandbox": "^5.9.4",
"@types/aws-lambda": "^8.10.130",
"@architect/sandbox": "^6.0.0-RC.1",
"@types/aws-lambda": "^8.10.132",
"@types/node": "18",
"cross-env": "~7.0.3",
"eslint": "^8.56.0",
"nyc": "~15.1.0",
"proxyquire": "~2.1.3",
"sinon": "^17.0.1",
"tap-arc": "^1.2.2",
"tap-spec": "^5.0.0",
"tape": "^5.7.2",
"tape": "^5.7.4",
"tiny-json-http": "^7.5.1",
"tsd": "^0.30.3"
"tsd": "^0.30.4"
},
"files": [
"types/*",
Expand Down
5 changes: 1 addition & 4 deletions src/discovery/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -30,10 +30,7 @@ module.exports = function lookup (callback) {
port = ports._arc
}
config = {
endpointPrefix: '/_arc/ssm',
host: `localhost`,
port,
protocol: 'http',
endpoint: `http://localhost:${port}/_arc/ssm`,
plugins,
}
}
Expand Down
4 changes: 1 addition & 3 deletions src/tables/factory.js
Original file line number Diff line number Diff line change
Expand Up @@ -28,9 +28,7 @@ module.exports = function factory ({ services, options = {} }, callback) {
return callback(ReferenceError('Sandbox tables port not found'))
}
let config = {
host: `localhost`,
port,
protocol: 'http',
endpoint: `http://localhost:${port}`,
region,
plugins,
}
Expand Down
4 changes: 4 additions & 0 deletions src/tables/legacy.js
Original file line number Diff line number Diff line change
Expand Up @@ -12,12 +12,15 @@ module.exports = function getLegacyDynamoClients ({ port, region }) {
let DB, Doc

if (isNode18) {
// eslint-disable-next-line
let dynamo = require('@aws-sdk/client-dynamodb')
// eslint-disable-next-line
let docclient = require('@aws-sdk/lib-dynamodb')
DB = dynamo.DynamoDB
Doc = docclient.DynamoDBDocument
}
else {
// eslint-disable-next-line
let dynamo = require('aws-sdk/clients/dynamodb')
DB = dynamo
Doc = dynamo.DocumentClient
Expand Down Expand Up @@ -50,6 +53,7 @@ module.exports = function getLegacyDynamoClients ({ port, region }) {
if (isNode18) {
// Disable keep-alive locally (or wait Node's default 5s for sockets to time out)
let http = require('http')
// eslint-disable-next-line
let { NodeHttpHandler } = require('@smithy/node-http-handler')
config.requestHandler = new NodeHttpHandler({
httpAgent: new http.Agent({ keepAlive: false })
Expand Down
3 changes: 1 addition & 2 deletions test/integration/tables-test.js
Original file line number Diff line number Diff line change
Expand Up @@ -11,10 +11,9 @@ let mock = join(__dirname, '..', 'mock')
let tmp = join(mock, 'tmp')
let shared = join(tmp, 'node_modules', '@architect', 'shared')


test('Set up mocked files', t => {
t.plan(3)
process.env.ARC_APP_NAME = 'test'
process.env.ARC_APP_NAME = 'test-app-name'
mkdir(shared, { recursive: true })
copyFileSync(join(mock, 'mock-arc'), join(shared, '.arc'))
copyFileSync(join(mock, 'mock-arc'), join(tmp, '.arc'))
Expand Down
9 changes: 9 additions & 0 deletions test/integration/ws-test.js
Original file line number Diff line number Diff line change
Expand Up @@ -20,11 +20,20 @@ test('Connect, get message, send message, get message, send disconnect, be disco

await new Promise(resolve => ws.once('open', resolve))
ws.send(JSON.stringify({ message: 'hi' }))

let infoMessage = await new Promise(resolve => ws.once('message', data => resolve(JSON.parse(data.toString('utf8')))))

t.equal(infoMessage.message, 'hi back')
t.equal(typeof infoMessage.info.ConnectedAt, 'string')

ws.send(JSON.stringify({ message: 'disconnect me' }))

await new Promise(resolve => ws.once('close', resolve))

// At this point, it may be normal to see Sandbox errors in the console, like 'WebSocket is not open: readyState 3 (CLOSED)'
// At this point in the test the @ws disconnect Lambda is just firing up, but we're about to shut down Sandbox, thereby creating a Lambda execution race condition
// We'll have to fix that at some point in the future by ensuring Sandbox shuts down invocations before terminating

t.pass('Disconnected')
})

Expand Down

0 comments on commit 941d797

Please sign in to comment.