Skip to content

Commit d4687c4

Browse files
committed
Move calls to new aws-lite endpoint param
If necessary, use dummy creds when running locally Update deps Use `tap-arc` Temporarily disable type testing, which is known to be broken at the moment
1 parent 4bff97b commit d4687c4

File tree

10 files changed

+44
-30
lines changed

10 files changed

+44
-30
lines changed

.github/workflows/build.yml

+4-4
Original file line numberDiff line numberDiff line change
@@ -45,10 +45,10 @@ jobs:
4545
env:
4646
CI: true
4747

48-
- name: Test types # this is kept out of "npm t" because it can be slow
49-
run: npm run test:types
50-
env:
51-
CI: true
48+
# - name: Test types # this is kept out of "npm t" because it can be slow
49+
# run: npm run test:types
50+
# env:
51+
# CI: true
5252

5353
- name: Notify
5454
uses: sarisia/actions-status-discord@v1

_changelog.md

+1-1
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,7 @@ Architect Functions just got a lot faster. Gone are the days of 500-1000ms cold
2525
- 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`
2626
- 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
2727
- This only really applies if your error handling relies on specific properties or values
28-
- 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
28+
- 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
2929
- 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
3030
- Added Node.js 20.x to test matrix
3131
- Breaking change: removed support for Node.js 14.x (now EOL, and no longer available to created in AWS Lambda)

package.json

+11-12
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{
22
"name": "@architect/functions",
3-
"version": "8.0.0-RC.1",
3+
"version": "8.0.0-RC.2",
44
"description": "Runtime utility library for Functional Web Apps (FWAs) built with Architect (https://arc.codes)",
55
"homepage": "https://github.com/architect/functions",
66
"repository": {
@@ -12,8 +12,8 @@
1212
"types": "types/index.d.ts",
1313
"scripts": {
1414
"lint": "eslint --fix .",
15-
"test:unit": "cross-env tape 'test/unit/**/*-test.js' | tap-spec",
16-
"test:integration": "cross-env tape 'test/integration/**/*-test.js' | tap-spec",
15+
"test:unit": "cross-env tape 'test/unit/**/*-test.js' | tap-arc",
16+
"test:integration": "cross-env tape 'test/integration/**/*-test.js' | tap-arc",
1717
"coverage": "nyc --reporter=lcov --reporter=text npm run test:unit",
1818
"test": "npm run lint && npm run test:integration && npm run coverage",
1919
"test:types": "tsd --files types/*.test-d.ts",
@@ -25,9 +25,9 @@
2525
"author": "Brian LeRoux <[email protected]>",
2626
"license": "Apache-2.0",
2727
"dependencies": {
28-
"@aws-lite/apigatewaymanagementapi": "^0.0.6",
29-
"@aws-lite/client": "^0.13.1",
30-
"@aws-lite/dynamodb": "^0.3.1",
28+
"@aws-lite/apigatewaymanagementapi": "^0.0.7",
29+
"@aws-lite/client": "^0.15.0",
30+
"@aws-lite/dynamodb": "^0.3.3",
3131
"@aws-lite/sns": "^0.0.4",
3232
"@aws-lite/sqs": "^0.2.0",
3333
"@aws-lite/ssm": "^0.2.2",
@@ -40,22 +40,21 @@
4040
"uid-safe": "^2.1.5"
4141
},
4242
"devDependencies": {
43-
"@architect/asap": "^6.0.4",
43+
"@architect/asap": "^7.0.0-RC.1",
4444
"@architect/eslint-config": "2.1.1",
4545
"@architect/req-res-fixtures": "git+https://github.com/architect/req-res-fixtures.git",
46-
"@architect/sandbox": "^5.9.4",
47-
"@types/aws-lambda": "^8.10.130",
46+
"@architect/sandbox": "^6.0.0-RC.1",
47+
"@types/aws-lambda": "^8.10.133",
4848
"@types/node": "18",
4949
"cross-env": "~7.0.3",
5050
"eslint": "^8.56.0",
5151
"nyc": "~15.1.0",
5252
"proxyquire": "~2.1.3",
5353
"sinon": "^17.0.1",
5454
"tap-arc": "^1.2.2",
55-
"tap-spec": "^5.0.0",
56-
"tape": "^5.7.2",
55+
"tape": "^5.7.4",
5756
"tiny-json-http": "^7.5.1",
58-
"tsd": "^0.30.3"
57+
"tsd": "^0.30.4"
5958
},
6059
"files": [
6160
"types/*",

src/discovery/index.js

+1-4
Original file line numberDiff line numberDiff line change
@@ -30,10 +30,7 @@ module.exports = function lookup (callback) {
3030
port = ports._arc
3131
}
3232
config = {
33-
endpointPrefix: '/_arc/ssm',
34-
host: `localhost`,
35-
port,
36-
protocol: 'http',
33+
endpoint: `http://localhost:${port}/_arc/ssm`,
3734
plugins,
3835
}
3936
}

src/lib/index.js

+11-2
Original file line numberDiff line numberDiff line change
@@ -11,14 +11,23 @@ function getAwsClient (params, callback) {
1111
params.region = process.env.AWS_REGION || 'us-west-2'
1212
awsLite(params)
1313
.then(client => callback(null, client))
14-
.catch(callback)
14+
.catch(err => {
15+
if (err.message.includes('AWS credentials') && !useAWS()) {
16+
let accessKeyId = 'arc_dummy_access_key'
17+
let secretAccessKey = 'arc_dummy_secret_key'
18+
awsLite({ ...params, accessKeyId, secretAccessKey })
19+
.then(client => callback(null, client))
20+
.catch(callback)
21+
}
22+
else callback(err)
23+
})
1524
}
1625

1726
function useAWS () {
1827
let { ARC_ENV, ARC_LOCAL, ARC_SANDBOX } = process.env
1928
// Testing is always local
2029
if (ARC_ENV === 'testing') return false
21-
// Local, but using AWS resources
30+
// Local, but using !testing environments
2231
if (nonLocalEnvs.includes(ARC_ENV) && ARC_SANDBOX && !ARC_LOCAL) return false
2332
// Assumed to be AWS
2433
return true

src/tables/factory.js

+1-3
Original file line numberDiff line numberDiff line change
@@ -28,9 +28,7 @@ module.exports = function factory ({ services, options = {} }, callback) {
2828
return callback(ReferenceError('Sandbox tables port not found'))
2929
}
3030
let config = {
31-
host: `localhost`,
32-
port,
33-
protocol: 'http',
31+
endpoint: `http://localhost:${port}`,
3432
region,
3533
plugins,
3634
}

src/tables/legacy.js

+4
Original file line numberDiff line numberDiff line change
@@ -12,12 +12,15 @@ module.exports = function getLegacyDynamoClients ({ port, region }) {
1212
let DB, Doc
1313

1414
if (isNode18) {
15+
// eslint-disable-next-line
1516
let dynamo = require('@aws-sdk/client-dynamodb')
17+
// eslint-disable-next-line
1618
let docclient = require('@aws-sdk/lib-dynamodb')
1719
DB = dynamo.DynamoDB
1820
Doc = docclient.DynamoDBDocument
1921
}
2022
else {
23+
// eslint-disable-next-line
2124
let dynamo = require('aws-sdk/clients/dynamodb')
2225
DB = dynamo
2326
Doc = dynamo.DocumentClient
@@ -50,6 +53,7 @@ module.exports = function getLegacyDynamoClients ({ port, region }) {
5053
if (isNode18) {
5154
// Disable keep-alive locally (or wait Node's default 5s for sockets to time out)
5255
let http = require('http')
56+
// eslint-disable-next-line
5357
let { NodeHttpHandler } = require('@smithy/node-http-handler')
5458
config.requestHandler = new NodeHttpHandler({
5559
httpAgent: new http.Agent({ keepAlive: false })

test/integration/discovery-test.js

+1-2
Original file line numberDiff line numberDiff line change
@@ -6,9 +6,8 @@ let mock = join(cwd, 'test', 'mock', 'project')
66
let discovery = require('../../src/discovery')
77

88
test('Set up env', async t => {
9-
t.plan(2)
9+
t.plan(1)
1010
await sandbox.start({ cwd: mock, quiet: true })
11-
t.pass('Set up ARC_APP_NAME env var')
1211
t.pass('Sandbox started')
1312
})
1413

test/integration/tables-test.js

+1-2
Original file line numberDiff line numberDiff line change
@@ -11,10 +11,9 @@ let mock = join(__dirname, '..', 'mock')
1111
let tmp = join(mock, 'tmp')
1212
let shared = join(tmp, 'node_modules', '@architect', 'shared')
1313

14-
1514
test('Set up mocked files', t => {
1615
t.plan(3)
17-
process.env.ARC_APP_NAME = 'test'
16+
process.env.ARC_APP_NAME = 'test-app-name'
1817
mkdir(shared, { recursive: true })
1918
copyFileSync(join(mock, 'mock-arc'), join(shared, '.arc'))
2019
copyFileSync(join(mock, 'mock-arc'), join(tmp, '.arc'))

test/integration/ws-test.js

+9
Original file line numberDiff line numberDiff line change
@@ -20,11 +20,20 @@ test('Connect, get message, send message, get message, send disconnect, be disco
2020

2121
await new Promise(resolve => ws.once('open', resolve))
2222
ws.send(JSON.stringify({ message: 'hi' }))
23+
2324
let infoMessage = await new Promise(resolve => ws.once('message', data => resolve(JSON.parse(data.toString('utf8')))))
25+
2426
t.equal(infoMessage.message, 'hi back')
2527
t.equal(typeof infoMessage.info.ConnectedAt, 'string')
28+
2629
ws.send(JSON.stringify({ message: 'disconnect me' }))
30+
2731
await new Promise(resolve => ws.once('close', resolve))
32+
33+
// At this point, it may be normal to see Sandbox errors in the console, like 'WebSocket is not open: readyState 3 (CLOSED)'
34+
// 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
35+
// We'll have to fix that at some point in the future by ensuring Sandbox shuts down invocations before terminating
36+
2837
t.pass('Disconnected')
2938
})
3039

0 commit comments

Comments
 (0)