cdk-ec2-controller
v0.1.0
Published
AWS CDK construct for API Gateway + Lambda + EC2 + SNS
Downloads
106
Readme
Welcome to your CDK TypeScript project
This is a blank project for CDK development with TypeScript.
The cdk.json file tells the CDK Toolkit how to execute your app.
Useful commands
npm run buildcompile typescript to jsnpm run watchwatch for changes and compilenpm run testperform the jest unit testsnpx cdk deploydeploy this stack to your default AWS account/regionnpx cdk diffcompare deployed stack with current statenpx cdk synthemits the synthesized CloudFormation template
aws-cdk-ec2-controller
AWS CDK construct to automate EC2 instance management via Lambda and API Gateway, with SNS notifications for all actions.
This stack allows you to:
- Start and stop EC2 instances programmatically.
- Fetch instance details (ID, Name, IP) via the
/detailsendpoint. - Send SNS notifications for all actions, including invalid requests.
- Expose a dev stage HTTP API with a catch-all route for guidance.
Features
- EC2 Control:
/startstarts all stopped instances,/stopstops all running instances. - Instance Details:
/detailsreturns a JSON list of instance IDs, names, and IPs. - SNS Notifications: Sends emails for every action and invalid requests.
- HTTP API Gateway: Dev stage included, with a catch-all route for guidance.
- Environment-Friendly: Lambda reads the SNS topic ARN from environment variables.
API Endpoints
| Path | Method | Description | |------------|--------|------------------------------------------| | /start | POST | Start all stopped EC2 instances | | /stop | POST | Stop all running EC2 instances | | /details | GET | Returns JSON with instance details | | * | POST | Catch-all: guides valid endpoints |
Installation
# Install via npm
npm install aws-cdk-ec2-controller
