Skip to content
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
14 changes: 10 additions & 4 deletions .github/workflows/integration.yml
Original file line number Diff line number Diff line change
Expand Up @@ -54,16 +54,22 @@ jobs:
name: artifacts-json-first-region
path: src

- name: Deploy the function on the published runtime too
if: inputs.published-layer
run: echo "BUN_CMR=1" >> "$GITHUB_ENV"

- name: Build the layer from source
if: ${{ !inputs.published-layer }}
run: |
bun run build:layer
echo "BUN_LAYER_ZIP=$PWD/lib/bun-lambda-layer-$(cat .bun-version).zip" >> "$GITHUB_ENV"

# PR runs have no fresh release, so the CMR echo function points at the runtime published
# by the latest GitHub release instead of the stack's region lookup.
- name: Resolve the published runtime for PR runs
if: ${{ !inputs.published-layer }}
run: |
curl -sSfL -o /tmp/artifacts.json \
https://github.com/${{ github.repository }}/releases/latest/download/artifacts.json
echo "BUN_RUNTIME_ARN=$(jq -r '.regions["eu-central-1"].runtimeArn' /tmp/artifacts.json)" >> "$GITHUB_ENV"
echo "BUN_RUNTIME_ALIAS=$(jq -r '.regions["eu-central-1"].runtimeAlias' /tmp/artifacts.json)" >> "$GITHUB_ENV"

- run: bun run build

- run: bun run integ:deploy-test-destroy
Expand Down
17 changes: 17 additions & 0 deletions command/cleanupIntegStacks.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
#!/bin/bash
# Destroys any leftover BunLayerInteg-* CloudFormation stacks, run by the integration
# workflow after the test (which should have destroyed its own stack already).
set -euo pipefail

stacks=$(aws cloudformation list-stacks \
--stack-status-filter CREATE_COMPLETE UPDATE_COMPLETE UPDATE_ROLLBACK_COMPLETE ROLLBACK_COMPLETE \
--query 'StackSummaries[].StackName' --output text)

for stack in $stacks; do
case "$stack" in
BunLayerInteg-*)
echo "Destroying $stack"
(cd examples/sample-app && INTEG_STACK_NAME="$stack" bunx cdk destroy "$stack" --force)
;;
esac
done
19 changes: 10 additions & 9 deletions examples/sample-app/lib/sample-stack.ts
Original file line number Diff line number Diff line change
Expand Up @@ -54,12 +54,15 @@ export class SampleStack extends Stack {
bunLayer,
});

// Echo on the customer-managed runtime. Needs the published runtime for the stack's region,
// so it is only deployed when BUN_CMR=1 (release runs).
const cmrEchoFn =
process.env.BUN_CMR === "1"
? new BunFunction(this, "CmrEchoFn", { entrypoint: src("echo.ts") })
: undefined;
// Echo on the customer-managed runtime (CMR) — no layer involved. Uses the published
// runtime for the stack's region by default; BUN_RUNTIME_ARN/BUN_RUNTIME_ALIAS override it
// for PR runs, which have no release yet and use artifacts.json from the latest GitHub release.
const runtimeArn = process.env.BUN_RUNTIME_ARN;
const runtimeAlias = process.env.BUN_RUNTIME_ALIAS;
const cmrEchoFn = new BunFunction(this, "CmrEchoFn", {
entrypoint: src("echo.ts"),
...(runtimeArn == null ? {} : { bunRuntime: { runtimeArn, runtimeAlias } }),
});

// Streaming — async generator handler, invoked via InvokeWithResponseStream
const streamingFn = new BunFunctionWithLayer(this, "StreamingFn", {
Expand Down Expand Up @@ -90,9 +93,7 @@ export class SampleStack extends Stack {
new CfnOutput(this, "HttpV2PlainFunctionUrl", { value: plainFnUrl.url });
new CfnOutput(this, "HttpV1RestApiUrl", { value: restApi.url });
new CfnOutput(this, "EchoFnArn", { value: echoFn.functionArn });
if (cmrEchoFn != null) {
new CfnOutput(this, "CmrEchoFnArn", { value: cmrEchoFn.functionArn });
}
new CfnOutput(this, "CmrEchoFnArn", { value: cmrEchoFn.functionArn });
new CfnOutput(this, "S3WriterFnArn", { value: s3WriterFn.functionArn });
new CfnOutput(this, "TestBucketName", { value: testBucket.bucketName });
new CfnOutput(this, "StreamingFnArn", { value: streamingFn.functionArn });
Expand Down
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -52,7 +52,7 @@
"lint": "oxlint .",
"test": "bun test",
"integ:deploy-test-destroy": "RUN_AWS_INTEG=1 bun test test/integration/deploy-destroy.test.ts",
"integ:cleanup": "bash -lc \"set -euo pipefail; stacks=$(aws cloudformation list-stacks --stack-status-filter CREATE_COMPLETE UPDATE_COMPLETE UPDATE_ROLLBACK_COMPLETE ROLLBACK_COMPLETE --query 'StackSummaries[].StackName' --output text); for stack in $stacks; do case \\\"$stack\\\" in BunLayerInteg-*) echo \\\"Destroying $stack\\\"; (cd examples/sample-app && INTEG_STACK_NAME=\\\"$stack\\\" bunx cdk destroy \\\"$stack\\\" --force);; esac; done\""
"integ:cleanup": "bash command/cleanupIntegStacks.sh"
},
"devDependencies": {
"@aws-sdk/client-lambda": "3.1077.0",
Expand Down
3 changes: 1 addition & 2 deletions test/integration/deploy-destroy.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@ interface StackOutputs {
HttpV2PlainFunctionUrl: string;
HttpV1RestApiUrl: string;
EchoFnArn: string;
CmrEchoFnArn?: string;
CmrEchoFnArn: string;
S3WriterFnArn: string;
TestBucketName: string;
StreamingFnArn: string;
Expand Down Expand Up @@ -129,7 +129,6 @@ describeInteg(
});

test("direct invoke echo on the customer-managed runtime", async () => {
if (outputs.CmrEchoFnArn == null) return;
const result = await invokeLambda(outputs.CmrEchoFnArn, { hello: "cmr" });
expect((result as { echo: unknown }).echo).toEqual({ hello: "cmr" });
});
Expand Down