Skip to content

Commit 7390fa7

Browse files
2 parents 2727625 + d1763d9 commit 7390fa7

File tree

94 files changed

+3706
-3616
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

94 files changed

+3706
-3616
lines changed

.github/workflows/build.yml

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -489,9 +489,7 @@ jobs:
489489
npm run build
490490
popd
491491
pushd examples/nodejs/aws/lambda-examples/advanced-compression
492-
# This example shows how to build and package a lambda function for a different target architecture,
493-
# and thus it requires this `--force` flag.
494-
npm ci --force
492+
npm ci
495493
npm run build
496494
popd
497495
pushd examples/nodejs/mongodb-examples/simple-read-aside

.github/workflows/retry-tests.yml

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -18,14 +18,15 @@ jobs:
1818

1919
- name: Start Momento Local
2020
run: |
21-
docker run -d -p 8080:8080 gomomento/momento-local
21+
docker run --cap-add=NET_ADMIN --rm -d -p 8080:8080 -p 9090:9090 gomomento/momento-local --enable-test-admin
2222
2323
- name: Set script permissions
2424
run: chmod +x ./scripts/build-and-test-package-retry-tests.sh
2525

2626
- name: Build and test with Momento Local
2727
env:
2828
MOMENTO_PORT: 8080
29+
MOMENTO_ADMIN_PORT: 9090
2930
run: |
3031
node -v
3132
./scripts/build-and-test-package-retry-tests.sh

.vscode/client-sdk-javascript.code-workspace

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -24,5 +24,9 @@
2424
"path": "../packages/common-integration-tests",
2525
"name": "packages/common-integration-tests",
2626
},
27+
{
28+
"path": "../examples/nodejs/aws/lambda-examples/advanced-compression",
29+
"name": "examples/nodejs/aws/lambda-examples/advanced-compression",
30+
}
2731
]
2832
}

examples/cloudflare-workers/web-sdk/package-lock.json

Lines changed: 8 additions & 8 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

examples/cloudflare-workers/web-sdk/package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@
1414
},
1515
"dependencies": {
1616
"@gomomento/sdk-core": "^1.40.0",
17-
"@gomomento/sdk-web": "^1.107.0",
17+
"@gomomento/sdk-web": "^1.108.0",
1818
"xhr4sw": "^0.0.5"
1919
}
2020
}

examples/nodejs/access-control/package-lock.json

Lines changed: 15 additions & 15 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

examples/nodejs/access-control/package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,7 @@
2626
"typescript": "4.9.5"
2727
},
2828
"dependencies": {
29-
"@gomomento/sdk": "^1.107.0",
29+
"@gomomento/sdk": "^1.108.0",
3030
"uuidv4": "6.2.13"
3131
}
3232
}

examples/nodejs/aws/eventbridge/cliApp/package-lock.json

Lines changed: 8 additions & 8 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

examples/nodejs/aws/eventbridge/cliApp/package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -27,7 +27,7 @@
2727
},
2828
"dependencies": {
2929
"@aws-sdk/client-dynamodb": "^3.596.0",
30-
"@gomomento/sdk": "^1.107.0",
30+
"@gomomento/sdk": "^1.108.0",
3131
"dotenv": "^16.4.5"
3232
},
3333
"engines": {

examples/nodejs/aws/eventbridge/webapp/package-lock.json

Lines changed: 8 additions & 8 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

examples/nodejs/aws/eventbridge/webapp/package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@
1010
"deploy": "npm install && cd - && cdk deploy"
1111
},
1212
"dependencies": {
13-
"@gomomento/sdk-web": "^1.107.0",
13+
"@gomomento/sdk-web": "^1.108.0",
1414
"aws-sdk": "^2.1628.0",
1515
"react": "^18.2.0",
1616
"react-dom": "^18.2.0",
Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
FROM amazonlinux:2023
2+
3+
# Install build dependencies
4+
RUN yum install -y zip && \
5+
curl -fsSL https://rpm.nodesource.com/setup_20.x | bash - && \
6+
yum install -y nodejs && \
7+
npm install -g node-gyp
8+
9+
WORKDIR /app
10+
11+
COPY package.json package-lock.json tsconfig.json esbuild.ts postbuild.ts ./
12+
COPY src ./src
13+
14+
RUN npm install --platform=linux --arch=x64
15+
RUN npm run build
16+
17+
CMD ["cp", "function.zip", "/output/"]

examples/nodejs/aws/lambda-examples/advanced-compression/README.md

Lines changed: 32 additions & 33 deletions
Original file line numberDiff line numberDiff line change
@@ -33,16 +33,12 @@ package the appropriate native `zstd` binary for your target environment. This e
3333
runtime, but assumes that you may be building / deploying the code from MacOS or another non-linux platform.
3434

3535
The `zstd` binaries are installed into the `node_modules` directory by `npm`. By default, `npm` will only install the appropriate
36-
binary for the platform that you are running the build from. To ensure that the correct binary for the target platform is
37-
also installed, you need to explicitly reference it in the `package.json` file. In this example, this is done via
38-
the following line in the `dependencies` section of our `package.json`:
36+
binary for the platform that you are running the build from. When developing locally, running `npm install` will do the right thing,
37+
but the lambda runtime is a different platform, so you need to ensure that the correct binary is included in the final package.
3938

40-
```json
41-
"@mongodb-js/zstd-linux-x64-gnu": "^1.2.0",
42-
```
43-
44-
If you were targeting a different platform, you could specify the appropriate dependency for your target platform here instead of
45-
the `linux-x64-gnu` version.
39+
Though not recommended for the normal development process, you may run `npm install --platform=linux --arch=x64`. This will
40+
install the correct binary for the lambda runtime. However, we recommend using a docker build to isolate the production
41+
build from your development environment (see [Building the Example](#building-the-example) below).
4642

4743
### `esbuild.ts`: Special handling for `.node` files
4844

@@ -57,28 +53,31 @@ you will need to take similar steps to ensure that the `.node` files are include
5753

5854
This script is responsible for creating the final `.zip` artifact that we will deploy to the lambda. It processes the
5955
`dist` directory created by `esbuild` and ensures that all the required files are present, and then produces the `.zip`.
60-
It also removes any unnecessary native binaries (`.node` files) that are not necessary for the target platform, to ensure
61-
that the final `.zip` is as small as possible.
62-
63-
**NOTE: this script has another hard coded reference to 'linux-x64-gnu' so that it knows the correct `.node` files to keep or
64-
remove. Therefore if you want to change the target platform, you will need to update the target architecture information in both
65-
the `package.json` file and the `postbuild.ts` file.**
6656

6757
## Building the Example
6858

69-
**NOTE: the `--force` flag is necessary on the `npm install` command if you are building from a different platform than
70-
the lambda target platform. Otherwise `npm` will error out and indicate that your platform and arch are not suitable
71-
for the `zstd-linux-x64-gnu` dependency that is listed in the `package.json` file.**
59+
### Production Build
7260

73-
To build the code and package the lambda .zip artifact:
61+
To build the code and package the lambda .zip artifact, run:
7462

7563
```bash
76-
npm install --force
77-
npm run build
64+
npm run build:aws
7865
```
7966

67+
**Note: this depends on docker to build the lambda package. See the script in [package.json](package.json) for details.**
68+
8069
At this point, you should have a `function.zip` file that contains the esbuild output and the linux x64 `zstd` binary.
8170

71+
### Local Development
72+
73+
In order to do local development, run:
74+
75+
```bash
76+
npm run build
77+
```
78+
79+
This will build the code and package but using a `node` binary that is appropriate for your local development environment.
80+
8281
## Deploy via AWS SAM
8382

8483
**NOTE: in this example project, we have the SAM `SkipBuild` metadata set to `True`, which means that the `sam build` command
@@ -106,18 +105,18 @@ lambda, then you won't need the `--force` flag, so you can allow SAM to manage t
106105
could modify the `template.yml` file to set `CodeUri` to `./src/index.ts`, and include this build metadata:
107106

108107
```yaml
109-
Metadata:
110-
SkipBuild: True
111-
BuildMethod: esbuild
112-
BuildProperties:
113-
UseNpmCi: true
114-
Minify: false
115-
Target: "es2020"
116-
Sourcemap: true
117-
Loader:
118-
- ".node=copy"
119-
EntryPoints:
120-
- src/index.ts
108+
Metadata:
109+
SkipBuild: True
110+
BuildMethod: esbuild
111+
BuildProperties:
112+
UseNpmCi: true
113+
Minify: false
114+
Target: "es2020"
115+
Sourcemap: true
116+
Loader:
117+
- ".node=copy"
118+
EntryPoints:
119+
- src/index.ts
121120
```
122121
123122
### Deploy Via AWS CLI

0 commit comments

Comments
 (0)