Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

aws-lite #722

Merged
merged 22 commits into from
Feb 2, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions .eslintignore
Original file line number Diff line number Diff line change
@@ -1,2 +1,3 @@
test/mock
scratch/
*-vendor.js
6 changes: 3 additions & 3 deletions .github/workflows/binary-build.yml
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ jobs:
runs-on: ${{ matrix.os }}
strategy:
matrix:
node-version: [ 14.x ]
node-version: [ 16.x ]
os: [ windows-latest, ubuntu-latest, macOS-latest ]

# Go
Expand All @@ -37,7 +37,7 @@ jobs:
- name: Set up Ruby
uses: ruby/setup-ruby@v1
with:
ruby-version: '2.7'
ruby-version: '3.2'

- name: Set up Deno
uses: denolib/setup-deno@v2
Expand Down Expand Up @@ -74,7 +74,7 @@ jobs:
- name: Notify
uses: sarisia/actions-status-discord@v1
# Only fire alert once
if: github.ref == 'refs/heads/main' && failure() && matrix.node-version == '14.x' && matrix.os == 'ubuntu-latest'
if: github.ref == 'refs/heads/main' && failure() && matrix.node-version == '20.x' && matrix.os == 'ubuntu-latest'
with:
webhook: ${{ secrets.DISCORD_WEBHOOK }}
title: "build and test"
Expand Down
6 changes: 3 additions & 3 deletions .github/workflows/build.yml
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ jobs:
runs-on: ${{ matrix.os }}
strategy:
matrix:
node-version: [ 14.x, 16.x, 18.x ]
node-version: [ 16.x, 18.x, 20.x ]
os: [ windows-latest, ubuntu-latest, macOS-latest ]

# Go
Expand Down Expand Up @@ -68,7 +68,7 @@ jobs:
- name: Notify
uses: sarisia/actions-status-discord@v1
# Only fire alert once
if: github.ref == 'refs/heads/main' && failure() && matrix.node-version == '14.x' && matrix.os == 'ubuntu-latest'
if: github.ref == 'refs/heads/main' && failure() && matrix.node-version == '20.x' && matrix.os == 'ubuntu-latest'
with:
webhook: ${{ secrets.DISCORD_WEBHOOK }}
title: "build and test"
Expand All @@ -92,7 +92,7 @@ jobs:
- name: Set up Node.js
uses: actions/setup-node@v3
with:
node-version: 16
node-version: lts/*
registry-url: https://registry.npmjs.org/

# Publish to npm
Expand Down
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ __pycache__
!test/mock/dep-warn/**/node_modules
.DS_Store
.nyc_output/
*-vendor.js
bin/*.json
bin/sandbox-binary*
chonky.txt
Expand Down
3 changes: 2 additions & 1 deletion bin/binary-config.js
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,8 @@ let config = {
'../node_modules/**/@architect/inventory/**/*.js',
],
assets: [
'../src/invoke-lambda/exec/runtimes/*'
'../src/invoke-lambda/exec/runtimes/*',
'../src/tables/_aws-lite-dynamodb-vendor.js',
],
targets: [],
outputPath: 'bin'
Expand Down
13 changes: 13 additions & 0 deletions changelog.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,19 @@

---

## [6.0.0] 2024-01-09

### Changed

- Transitioned from `aws-sdk` to [`aws-lite`](https://aws-lite.org)
- Breaking change: Sandbox no longer includes `aws-sdk` + `@aws-sdk/*` as dependencies; projects that rely on the AWS SDK should install those dependencies to their project directly
- Breaking change: `nodejs20.x` and `python3.12` are now the default Node.js and Python Lambda runtimes, respectively
- Breaking change: removed support for Node.js 14.x (now EOL, and no longer available to created in AWS Lambda)
- Added Node.js 20.x to test matrix
- Updated dependencies

---

## [5.9.4] 2023-11-20

### Changed
Expand Down
39 changes: 17 additions & 22 deletions package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "@architect/sandbox",
"version": "5.9.4",
"version": "6.0.0-RC.4",
"description": "Architect dev server: run full Architect projects locally & offline",
"main": "src/index.js",
"scripts": {
Expand All @@ -10,7 +10,7 @@
"coverage": "nyc --reporter=lcov --reporter=text npm run test:unit",
"lint": "eslint . --fix",
"rc": "npm version prerelease --preid RC",
"build": "node bin/binary-config.js && npx pkg bin"
"build": "node scripts/vendor.js && node bin/binary-config.js && npx pkg bin"
},
"engines": {
"node": ">=14"
Expand All @@ -28,29 +28,22 @@
"src/*"
],
"dependencies": {
"@architect/asap": "~6.0.4",
"@architect/create": "~4.2.4",
"@architect/hydrate": "~3.5.1",
"@architect/inventory": "~3.6.3",
"@architect/utils": "~3.1.9",
"@aws-sdk/client-apigatewaymanagementapi": "^3.316.0",
"@aws-sdk/client-dynamodb": "^3.316.0",
"@aws-sdk/client-s3": "^3.316.0",
"@aws-sdk/client-sns": "^3.316.0",
"@aws-sdk/client-sqs": "^3.316.0",
"@aws-sdk/client-ssm": "^3.316.0",
"@aws-sdk/lib-dynamodb": "^3.316.0",
"@aws-sdk/node-http-handler": "^3.360.0",
"@architect/asap": "~7.0.0",
"@architect/create": "~5.0.0",
"@architect/hydrate": "~4.0.0",
"@architect/inventory": "~4.0.0",
"@architect/utils": "~4.0.0",
"@aws-lite/client": "^0.15.2",
"@aws-lite/dynamodb": "^0.3.3",
"@begin/hashid": "~1.0.0",
"aws-sdk": "^2.1363.0",
"chalk": "4.1.2",
"chokidar": "~3.5.3",
"depstatus": "~1.1.1",
"dynalite": "~3.2.2",
"finalhandler": "~1.2.0",
"glob": "~10.3.10",
"http-proxy": "~1.18.1",
"lambda-runtimes": "~1.1.6",
"lambda-runtimes": "~2.0.1",
"minimist": "~1.2.8",
"router": "~1.3.8",
"run-parallel": "~1.2.0",
Expand All @@ -60,20 +53,22 @@
"tmp": "~0.2.1",
"tree-kill": "~1.2.2",
"update-notifier-cjs": "~5.1.6",
"ws": "~8.14.2"
"ws": "~8.16.0"
},
"devDependencies": {
"@architect/eslint-config": "~2.1.2",
"@architect/functions": "~7.0.0",
"@architect/functions": "~8.0.0-RC.3",
"@architect/req-res-fixtures": "git+https://github.com/architect/req-res-fixtures.git",
"@aws-lite/apigatewaymanagementapi": "~0.0.7",
"@aws-lite/ssm": "~0.2.2",
"cross-env": "~7.0.3",
"eslint": "~8.54.0",
"fs-extra": "~11.1.1",
"eslint": "~8.56.0",
"fs-extra": "~11.2.0",
"nyc": "~15.1.0",
"pkg": "~5.8.1",
"proxyquire": "~2.1.3",
"tap-arc": "~1.2.2",
"tape": "~5.7.2",
"tape": "~5.7.4",
"tiny-json-http": "~7.5.1"
},
"eslintConfig": {
Expand Down
1 change: 1 addition & 0 deletions scripts/.npmrc
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
package-lock=false
4 changes: 4 additions & 0 deletions scripts/aws-lite-dynamodb.mjs
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
import dynamo from '@aws-lite/dynamodb'
export const service = dynamo.service
export const property = dynamo.property
export const methods = dynamo.methods
5 changes: 5 additions & 0 deletions scripts/package.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
{
"dependencies": {
"esbuild": "^0.19.5"
}
}
8 changes: 8 additions & 0 deletions scripts/vendor.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
#! /usr/bin/env node

let { execSync } = require('child_process')
let cwd = __dirname
let options = { cwd, stdio: 'inherit' }

execSync('npm install --force --omit=dev', options)
execSync('npx esbuild ./aws-lite-dynamodb.mjs --bundle --platform=node --format=cjs --outfile=../src/tables/_aws-lite-dynamodb-vendor.js', options)
5 changes: 5 additions & 0 deletions scripts/vendor.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
cd scripts

npm install --force --omit=dev

npx esbuild ./aws-lite-dynamodb.mjs --bundle --platform=node --format=cjs --outfile=../src/tables/_aws-lite-dynamodb-vendor.js
1 change: 1 addition & 0 deletions src/arc/_ssm/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -101,6 +101,7 @@ module.exports = function _ssm ({ body, services }, params, req, res) {
update.verbose.warn(err)
res.statusCode = 400
error = error || { __type: 'InternalServerError', message: 'Unknown Sandbox error: ' + err.stack }
res.setHeader('content-type', 'application/json')
res.end(JSON.stringify(error))
return
}
Expand Down
3 changes: 1 addition & 2 deletions src/cli/arc.js
Original file line number Diff line number Diff line change
Expand Up @@ -7,9 +7,8 @@ let cli = require('./index.js')
module.exports = function arcCalling ({ inventory }) {
cli({
disableBanner: true,
needsValidCreds: false,
runtimeCheck: 'warn',
inventory,
runtimeCheck: 'warn',
},
function _done (err) {
if (err) {
Expand Down
4 changes: 3 additions & 1 deletion src/http/middleware/_fallback.js
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ let httpProxy = require('http-proxy')
* - Error out
*/
module.exports = function fallback (args, req, res, next) {
let { apiType, cwd, inventory, ports, staticPath, update } = args
let { apiType, creds, cwd, inventory, ports, staticPath, update } = args
let { inv, get } = inventory
let httpAPI = apiType.startsWith('http')
let method = req.method.toLowerCase()
Expand Down Expand Up @@ -111,6 +111,7 @@ module.exports = function fallback (args, req, res, next) {
let name = `${rootParam[0]} /${rootParam[1]}`
let lambda = get.http(name)
let exec = invoker({
creds,
cwd,
lambda,
apiType,
Expand Down Expand Up @@ -144,6 +145,7 @@ module.exports = function fallback (args, req, res, next) {
function invokeProxy (src, arcStaticAssetProxy) {
let exec = invoker({
apiType,
creds,
cwd,
lambda: {
name: 'get /*',
Expand Down
11 changes: 6 additions & 5 deletions src/invoke-lambda/env/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -5,10 +5,11 @@ let { version } = require('../../../package.json')

// Assemble Lambda-specific execution environment variables
module.exports = function getEnv (params, requestID) {
let { apiType, cwd, lambda, host, inventory, ports, staticPath } = params
let { apiType, creds, cwd, lambda, host, inventory, ports, staticPath } = params
let { accessKeyId, secretAccessKey, sessionToken } = creds
let { config, src, build, handlerFile } = lambda
let { inv } = inventory
let { AWS_ACCESS_KEY_ID, AWS_PROFILE, AWS_REGION, AWS_SECRET_ACCESS_KEY, AWS_SESSION_TOKEN, PATH } = process.env
let { AWS_PROFILE, AWS_REGION, PATH } = process.env

let lambdaContext = getContext(params)
let envVars = userEnvVars(params)
Expand All @@ -23,16 +24,16 @@ module.exports = function getEnv (params, requestID) {
// Runtime environment variables
let env = {
// AWS-specific
AWS_ACCESS_KEY_ID,
AWS_ACCESS_KEY_ID: accessKeyId,
AWS_LAMBDA_FUNCTION_MEMORY_SIZE: lambda.config.memory,
AWS_LAMBDA_FUNCTION_NAME: `@${lambda.pragma} ${lambda.name}`,
AWS_LAMBDA_FUNCTION_VERSION: '$latest',
AWS_LAMBDA_RUNTIME_API,
AWS_PROFILE,
AWS_REGION,
AWS_SDK_JS_SUPPRESS_MAINTENANCE_MODE_MESSAGE: true, // Sigh.
AWS_SECRET_ACCESS_KEY,
AWS_SESSION_TOKEN,
AWS_SECRET_ACCESS_KEY: secretAccessKey,
AWS_SESSION_TOKEN: sessionToken,
LAMBDA_TASK_ROOT: src,
TZ: 'UTC',
// Internal for handler bootstrap
Expand Down
25 changes: 25 additions & 0 deletions src/sandbox/creds.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
let awsLite = require('@aws-lite/client')
module.exports = function loadCreds (params, callback) {
let { inventory } = params
awsLite({
autoloadPlugins: false,
profile: inventory.inv?.aws?.profile,
region: 'us-west-1', // Region doesn't matter, we just need to get creds
})
.then(aws => {
params.creds = {
// secretAccessKey + sessionToken are non-enumerable, so we can't just ref or spread
accessKeyId: aws.credentials.accessKeyId,
secretAccessKey: aws.credentials.secretAccessKey,
sessionToken: aws.credentials.sessionToken,
}
callback()
})
.catch(() => {
params.creds = {
accessKeyId: 'arc_dummy_access_key',
secretAccessKey: 'arc_dummy_secret_key',
}
callback()
})
}
13 changes: 7 additions & 6 deletions src/sandbox/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ let series = require('run-series')
let create = require('@architect/create')

let env = require('./env')
let creds = require('./creds')
let ports = require('./ports')
let checkRuntimes = require('./check-runtimes')
let maybeHydrate = require('./maybe-hydrate')
Expand All @@ -27,6 +28,11 @@ function _start (params, callback) {
env(params, callback)
},

// Load credentials
function (callback) {
creds(params, callback)
},

// Get the ports for services
function (callback) {
ports(params, callback)
Expand Down Expand Up @@ -107,12 +113,7 @@ function _start (params, callback) {
],
function (err) {
if (err) callback(err)
else {
if (process.env.ARC_AWS_CREDS === 'dummy' && !restart) {
update.verbose.warn('Missing or invalid AWS credentials or credentials file, using dummy credentials (this is probably ok)')
}
callback(null, params.ports)
}
else callback(null, params.ports)
})
}

Expand Down
12 changes: 8 additions & 4 deletions src/sandbox/seed.js
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ let getDBClient = require('../tables/_get-db-client')

module.exports = function startupSeedData (params, callback) {
let { ARC_ENV } = process.env
let { cwd, inventory, update, ports } = params
let { creds, cwd, inventory, update, ports } = params
let { inv, get } = inventory
let { app, tables } = inv
if (!tables || ARC_ENV !== 'testing') return callback()
Expand Down Expand Up @@ -47,13 +47,17 @@ module.exports = function startupSeedData (params, callback) {
return
}
let TableName = `${app}-staging-${table}`
return rows.map(Item => callback => dynamo.put({ TableName, Item }, callback))
return rows.map(Item => callback => {
dynamo.PutItem({ TableName, Item })
.then(result => callback(null, result))
.catch(callback)
})
}).filter(Boolean)

getDBClient(ports, (err, db, doc) => {
getDBClient({ creds, inventory, ports }, (err, aws) => {
if (err) callback(err)
else {
dynamo = doc
dynamo = aws.DynamoDB
let start = Date.now()
series(seeds, (err) => {
if (err) callback(err)
Expand Down
Loading
Loading