feat: Sample Node.js REST API with AWS CDK — EC2 + API Gateway, GitLab CI/CD#36
Open
devin-ai-integration[bot] wants to merge 8 commits intomainfrom
Open
feat: Sample Node.js REST API with AWS CDK — EC2 + API Gateway, GitLab CI/CD#36devin-ai-integration[bot] wants to merge 8 commits intomainfrom
devin-ai-integration[bot] wants to merge 8 commits intomainfrom
Conversation
- Express.js REST API with CRUD endpoints wrapped in @vendia/serverless-express - AWS CDK stack with Lambda + API Gateway + Provisioned Concurrency (no cold starts) - Auto-scaling provisioned concurrency (2-10 instances at 70% utilization) - ARM64 architecture + esbuild bundling for optimized cold start times - GitLab CI/CD pipeline (.gitlab-ci.yml) with validate/test/build/deploy stages - Jest test suite for CDK stack assertions - TypeScript + ESLint configuration
Contributor
Author
🤖 Devin AI EngineerI'll be helping with this pull request! Here's what you should know: ✅ I will automatically:
Note: I can only respond to comments from users who have write access to this repository. ⚙️ Control Options:
|
- Replace all .ts files with .js equivalents (CommonJS require/module.exports) - Remove TypeScript dependencies (typescript, ts-node, ts-jest, @types/*) - Remove tsconfig.json - Update cdk.json to use 'node bin/app.js' instead of ts-node - Update .gitlab-ci.yml: remove typecheck stage - Update .eslintrc.json: remove TS parser/plugins - Update jest.config.js: remove ts-jest transform - Update .gitignore: no longer ignore *.js files - Update README for JS project structure
- Replace Lambda + Provisioned Concurrency with EC2 (t3.micro) + API Gateway HTTP API - EC2 runs Express.js via systemd (auto-restart, always-on, zero cold start) - API Gateway HTTP API with direct HTTP proxy to EC2 public IP (no VPC Link, no NLB) - VPC with public subnets, security group allowing port 3000 and SSH - IAM role with SSM Session Manager for secure access - UserData bootstraps Node.js 20, Express app, and systemd service - Remove Lambda/esbuild/serverless-express dependencies - Update tests (8 passing) for EC2 architecture - Update README with EC2 architecture diagram and docs
- Update bin/app.js description: EC2 with API Gateway HTTP API - Update .gitlab-ci.yml comment: EC2 + API Gateway - Remove src/handler.js (Lambda handler, no longer needed)
- CDK now uploads src/ as an S3 Asset instead of inlining Express code in UserData - EC2 UserData downloads the same src/ code from S3 at boot time - Single source of truth: src/local.js is used by both local dev and EC2 systemd - Grant EC2 IAM role S3 read access for asset buckets - Remove stale handler.js reference from README - Update tests to verify S3 asset IAM policy (9 passing)
- Install PM2 globally in UserData - Start Express app with pm2 start (auto-restart, log management) - pm2 save + pm2 startup for boot persistence - Simpler and more Node.js-native than systemd
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary
Adds a new
sample-nodejs-cdk-api/project — a plain JavaScript (CommonJS) Node.js REST API deployed on EC2 behind API Gateway HTTP API, using AWS CDK for infrastructure and GitLab CI/CD for automated deployment. Zero cold start — Express.js runs continuously on EC2 via PM2 (auto-restart, log management, boot persistence).Architecture:
Key components:
/api/itemsendpoints on EC2src/andpackage.jsonas S3 assets; EC2 UserData downloads and runs them — single source of truth, no duplicated app codepm2 start, saves the process list, and configurespm2 startupfor boot persistence.gitlab-ci.ymlwith validate → test → build → deploy stages (dev/staging/prod)Review & Testing Checklist for Human
unzip -o /tmp/app-code.zip -d /home/ec2-user/app/src/. The directory structure inside the zip depends on how CDK packages thesrc/directory. If CDK nests it, files may land at.../src/src/app.jsinstead of.../src/app.js. Deploy to a test account and verify the extracted file paths — this is the highest-risk item since it determines whether the app actually starts.instance.instancePublicDnsName, which changes when the EC2 instance is stopped and restarted. This silently breaks the API Gateway route. Consider adding an Elastic IP to stabilize the integration URI.package.jsonincludesaws-cdk-libandconstructsas regulardependencies. These are only needed for CDK synthesis, not at Express runtime, butnpm install --omit=devwill still install them (~200 MB). Consider a separate runtimepackage.jsonor moving CDK libs todevDependencies.anyIpv4(). For production, restrict to specific CIDRs or remove entirely (SSM Session Manager is already configured via the IAM role)..gitlab-ci.ymlassumes it runs at the project root, but the code lives insample-nodejs-cdk-api/. If this stays as a subdirectory, every CI job needs acd sample-nodejs-cdk-apior equivalent.Suggested test plan:
cd sample-nodejs-cdk-api && npm installnpm run devand hithttp://localhost:3000/api/itemsto verify CRUD locallynpx cdk synth --context env=devand inspect the CloudFormation template — check the UserData script for correct S3 paths and PM2 commandsnpx cdk deploy --context env=devpm2 listandpm2 logsto verify PM2 is running the app/home/ec2-user/app/src/contains the expected files (app.js,local.js,routes/)http://<public-ip>:3000/) return valid responsesNotes
.gitlab-ci.ymlis designed for a standalone repo. If this subdirectory layout is kept, each CI job needsworking_dir: sample-nodejs-cdk-apior equivalent.Map— data is lost on EC2 restart. Intentional for a sample app; swap in DynamoDB/RDS for persistence.Link to Devin session: https://partner-workshops.devinenterprise.com/sessions/898695fe95d84a8fa616c239eedd0166