Skip to content

Commit

Permalink
feat: add SQS support (#34)
Browse files Browse the repository at this point in the history
  • Loading branch information
skyrpex authored Mar 9, 2024
1 parent 773bf0e commit fdb76bc
Show file tree
Hide file tree
Showing 30 changed files with 3,130 additions and 2,533 deletions.
12 changes: 12 additions & 0 deletions .editorconfig
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
root = true

[*]
indent_style = space
indent_size = 2
end_of_line = lf
charset = utf-8
trim_trailing_whitespace = true
insert_final_newline = true

[*.md]
trim_trailing_whitespace = false
14 changes: 4 additions & 10 deletions .github/actions/build/action.yml
Original file line number Diff line number Diff line change
Expand Up @@ -3,29 +3,23 @@ description: "Setup Project"
runs:
using: "composite"
steps:
- uses: actions/checkout@v3

- uses: pnpm/action-setup@v2
- uses: pnpm/action-setup@v3
with:
version: 6.32.9
version: 8

- uses: actions/setup-node@v3
with:
node-version: "18"
node-version: "20"
cache: "pnpm"

- uses: pnpm/[email protected]
with:
version: 7.13.5

- run: pnpm install --frozen-lockfile
shell: bash

- name: Ensure no changes
run: git diff --exit-code
shell: bash

- name: "Generate"
- name: Generate
run: pnpm generate
shell: bash

Expand Down
17 changes: 7 additions & 10 deletions .github/workflows/build.yml
Original file line number Diff line number Diff line change
@@ -1,24 +1,21 @@
name: build
on:
pull_request: {}
workflow_call:
secrets:
AWS_ACCESS_KEY_ID:
required: true
AWS_SECRET_ACCESS_KEY:
required: true
jobs:
build:
runs-on: ubuntu-latest
concurrency: build
env:
CI: "true"
CLEAN_UP_STACK: "1"
steps:
- uses: actions/checkout@v3

- uses: ./.github/actions/build

- name: Start LocalStack
uses: LocalStack/[email protected]
with:
image-tag: "latest"

- name: Run tests
run: pnpm test
env:
AWS_ACCESS_KEY_ID: ${{ secrets.AWS_ACCESS_KEY_ID }}
AWS_SECRET_ACCESS_KEY: ${{ secrets.AWS_SECRET_ACCESS_KEY }}
3 changes: 2 additions & 1 deletion .gitignore
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
lib/
/dist/
/benchmark/infra/lib/
node_modules/
sdk.generated.ts
.bundle
Expand Down
14 changes: 12 additions & 2 deletions CONTRIBUTING.md
Original file line number Diff line number Diff line change
Expand Up @@ -44,11 +44,21 @@ The tests require that you have credentials in your environment variables:

- `AWS_ACCESS_KEY_ID`
- `AWS_SECRET_ACCESS_KEY`
- `AWS_REGION`

Alternatively, you can use LocalStack with docker:

```sh
docker run \
--rm -it \
-p 4566:4566 \
-p 4510-4559:4510-4559 \
localstack/localstack
```

The test procedure is as follows:

1. run [`./test/setup.ts`](./test/setup.ts) to create AWS Resources for running tests again. See the [./test/constants.ts](./test/constants.ts) for the names (e.g. DynamoDB Table name) of Resources that will be created. This script uses `itty-aws` itself to create the Resources, so they also act as tests for the AWS Control Plane.
2. Run `jest` which will run all the tests in [`./test/**.test.ts`](./test/). The tests will interact with Resources, putting and getting data, acting as tests for the AWS Data Plane.
- Run `vitest` which will run all the tests in [`./test/**.test.ts`](./test/). The tests will create and interact with Resources, putting and getting data, acting as tests for the AWS Data Plane.

## Benchmark

Expand Down
6 changes: 3 additions & 3 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -11,9 +11,9 @@ Known to work:
- ✅ Any modern API using plain JSON protocol should work out of the box.
- ✅ DynamoDB
- ✅ EventBridge
- ✅ SQS
- ✅ S3 `CreateBucket`, `GetObject`, `HeadObject`, `PutObject`, `DeleteObject`, `ListObjectsV2`
- ⛔️ S3 the remaining S3 APis likely don't work due to inconsistencies in the XML API.
- ⛔️ SQS (see: [#1](https://github.com/sam-goodwin/itty-aws/issues/1))
- ⛔️ SNS (see: [#2](https://github.com/sam-goodwin/itty-aws/issues/2))

## Why?
Expand All @@ -33,8 +33,8 @@ This project aims to eliminate the following issues with the official AWS SDK:

The entire AWS SDK (including all Services and APIs) fits in to a

- Minified bundle size of: `49 KB`.
- Un-minified bundle size of: `95 KB`.
- Minified bundle size of: `22 KB`.
- Un-minified bundle size of: `32 KB`.

> 💪 It is possible to reduce this even further.
Expand Down
1 change: 1 addition & 0 deletions benchmark/functions/.gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
/dist/
10 changes: 8 additions & 2 deletions benchmark/functions/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -3,8 +3,14 @@
"version": "0.0.0",
"private": true,
"type": "module",
"scripts": {
"build": "tsup src/*.ts --format esm --target esnext"
},
"dependencies": {
"itty-aws": "workspace:^",
"@aws-sdk/client-dynamodb": "^3.245.0"
"@aws-sdk/client-dynamodb": "^3.245.0",
"itty-aws": "workspace:^"
},
"devDependencies": {
"tsup": "^8.0.1"
}
}
5 changes: 2 additions & 3 deletions benchmark/functions/tsconfig.json
Original file line number Diff line number Diff line change
@@ -1,9 +1,8 @@
{
"extends": "../../tsconfig.base.json",
"extends": "../../tsconfig.json",
"include": ["src"],
"exclude": ["lib", "node_modules"],
"compilerOptions": {
"outDir": "lib"
},
"references": [{ "path": "../../tsconfig.esm.json" }]
}
}
6 changes: 3 additions & 3 deletions benchmark/infra/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -8,14 +8,14 @@
"hotswap": "cdk deploy --hotswap"
},
"dependencies": {
"aws-cdk-lib": "^2.60.0",
"@benchmark/functions": "workspace:^"
"@benchmark/functions": "workspace:^",
"aws-cdk-lib": "^2.60.0"
},
"devDependencies": {
"@types/node": "^16",
"aws-cdk": "^2.60.0",
"constructs": "^10",
"ts-node": "^10.9.1",
"typescript": "^4.9.4"
"typescript": "^5.3.2"
}
}
12 changes: 6 additions & 6 deletions benchmark/infra/src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@ const props = {
const ittyFunc = new aws_lambda_nodejs.NodejsFunction(stack, "IttyFunc", {
functionName: "benchmark-itty",
runtime: aws_lambda.Runtime.NODEJS_18_X,
entry: require.resolve("@benchmark/functions/lib/itty-handler"),
entry: require.resolve("@benchmark/functions/dist/itty-handler"),
bundling: {
externalModules: ["@aws-sdk/*"],
},
Expand All @@ -40,7 +40,7 @@ const ittyFunc = new aws_lambda_nodejs.NodejsFunction(stack, "IttyFunc", {
const v2Func = new aws_lambda_nodejs.NodejsFunction(stack, "V2", {
functionName: "benchmark-v2",
runtime: aws_lambda.Runtime.NODEJS_16_X,
entry: require.resolve("@benchmark/functions/lib/v2-handler"),
entry: require.resolve("@benchmark/functions/dist/v2-handler"),
bundling: {
externalModules: ["aws-sdk"],
},
Expand All @@ -51,7 +51,7 @@ const v2Func = new aws_lambda_nodejs.NodejsFunction(stack, "V2", {
const v3BundledFunc = new aws_lambda_nodejs.NodejsFunction(stack, "V3Bundled", {
functionName: "benchmark-v3-bundled",
runtime: aws_lambda.Runtime.NODEJS_18_X,
entry: require.resolve("@benchmark/functions/lib/v3-handler"),
entry: require.resolve("@benchmark/functions/dist/v3-handler"),
bundling: {
externalModules: [],
},
Expand All @@ -65,7 +65,7 @@ const v3ExcludedFunc = new aws_lambda_nodejs.NodejsFunction(
{
functionName: "benchmark-v3-excluded",
runtime: aws_lambda.Runtime.NODEJS_18_X,
entry: require.resolve("@benchmark/functions/lib/v3-handler"),
entry: require.resolve("@benchmark/functions/dist/v3-handler"),
bundling: {
externalModules: ["@aws-sdk/*"],
},
Expand All @@ -80,7 +80,7 @@ const v3ExcludedMonoFunc = new aws_lambda_nodejs.NodejsFunction(
{
functionName: "benchmark-v3-mono-excluded",
runtime: aws_lambda.Runtime.NODEJS_18_X,
entry: require.resolve("@benchmark/functions/lib/v3-mono-lambda"),
entry: require.resolve("@benchmark/functions/dist/v3-mono-handler"),
bundling: {
externalModules: ["@aws-sdk/*"],
},
Expand All @@ -95,7 +95,7 @@ const v3BundledMonoFunc = new aws_lambda_nodejs.NodejsFunction(
{
functionName: "benchmark-v3-mono-bundled",
runtime: aws_lambda.Runtime.NODEJS_18_X,
entry: require.resolve("@benchmark/functions/lib/v3-mono-lambda"),
entry: require.resolve("@benchmark/functions/dist/v3-mono-handler"),
bundling: {
externalModules: [],
},
Expand Down
5 changes: 3 additions & 2 deletions benchmark/infra/tsconfig.json
Original file line number Diff line number Diff line change
@@ -1,11 +1,12 @@
{
"extends": "../../tsconfig.base.json",
"extends": "../../tsconfig.json",
"include": ["src"],
"exclude": ["lib", "node_modules"],
"compilerOptions": {
"outDir": "lib",
"module": "CommonJS",
"moduleResolution": "Node",
"target": "ES2022"
"target": "ES2022",
"verbatimModuleSyntax": false
}
}
48 changes: 14 additions & 34 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -2,19 +2,19 @@
"name": "itty-aws",
"version": "0.0.9",
"files": [
"lib"
"dist"
],
"type": "module",
"module": "./lib/index.js",
"types": "./lib/index.d.ts",
"module": "./dist/index.js",
"types": "./dist/index.d.ts",
"scripts": {
"download:models": "bash ./scripts/download-smithy-models.sh",
"generate": "pnpm generate:types && pnpm generate:mappings",
"generate:types": "ts-node-esm ./scripts/gen-sdk-types.mts",
"generate:mappings": "ts-node-esm ./scripts/gen-sdk-mappings.mts",
"build": "tsc -b",
"test": "ts-node-esm --project ./tsconfig.esm.json ./test/setup.ts && NODE_OPTIONS=--experimental-vm-modules jest",
"watch": "tsc -b -w",
"generate:types": "tsx ./scripts/gen-sdk-types.mts",
"generate:mappings": "tsx ./scripts/gen-sdk-mappings.mts",
"build": "tsup src/index.ts --format esm --target esnext --dts",
"test": "vitest run",
"watch": "tsup src/index.ts --format esm --target esnext --watch",
"analyze:bundle": "sh ./scripts/analyze-bundle.sh",
"bench:synth": "pnpm -r --filter @benchmark/infra synth",
"bench:deploy": "pnpm -r --filter @benchmark/infra run deploy",
Expand All @@ -37,35 +37,15 @@
"@aws-sdk/protocol-http": "3.226.0",
"@aws-sdk/signature-v4": "3.226.0",
"@aws-sdk/types": "3.226.0",
"@tsconfig/node16": "^1",
"@types/jest": "^29",
"@types/node": "^16",
"@types/prettier": "^2.7.2",
"@types/node": "^20",
"esbuild": "0.17.2",
"esbuild-visualizer": "^0.4.0",
"jest": "^29",
"node-fetch": "^3.3.0",
"prettier": "^2.8.3",
"prettier": "^3.2.4",
"standard-version": "^9.5.0",
"ts-jest": "^29",
"ts-node": "^10.9.1",
"typescript": "^4.9.4"
},
"jest": {
"extensionsToTreatAsEsm": [
".ts"
],
"moduleNameMapper": {
"^(\\.{1,2}/.*)\\.js$": "$1"
},
"transform": {
"^.+\\.(t|j)sx?$": [
"ts-jest",
{
"tsconfig": "tsconfig.test.json",
"useESM": true
}
]
}
"tsup": "^8.0.1",
"tsx": "^4.6.0",
"typescript": "^5.3.2",
"vitest": "^1.2.2"
}
}
Loading

0 comments on commit fdb76bc

Please sign in to comment.