An AWS Labs Model Context Protocol (MCP) server for managing AWS EC2 instances, AMIs, security groups, volumes, snapshots, and related infrastructure with cost-effective KMS-encrypted key pair storage
Project description
AWS EC2 MCP Server
A Model Context Protocol (MCP) server for managing AWS EC2 instances, AMIs, security groups, volumes, and related infrastructure with cost-effective KMS-encrypted key pair storage.
Features
This MCP server acts as a bridge between MCP clients and AWS EC2, allowing generative AI models to create, configure, and manage EC2 resources. The server provides a secure way to interact with AWS EC2 resources while maintaining proper access controls and resource validation.
Core Capabilities
- EC2 Instances: Launch, terminate, start, stop, and reboot instances
- Security Groups: Create, modify, and delete security groups and rules
- Key Pairs: Create and manage SSH key pairs with secure storage
- EBS Volumes: Create, attach, detach, and delete volumes
- EBS Snapshots: Create and manage volume snapshots
- AMIs: Create custom AMIs from instances and manage their lifecycle
- VPC Management: List and manage VPCs, subnets, and networking components
Security Features
- Input validation for all AWS resource IDs
- Permission-based access control with environment variable controls
- Response sanitization to prevent sensitive data leakage
- Secure private key storage with KMS encryption (S3), Secrets Manager, or Parameter Store
- Cost-effective KMS encryption for S3 storage (99.9% cheaper than Secrets Manager)
- Configurable write operation protection
Prerequisites
- AWS account with permissions to manage EC2 resources
- AWS credentials configured (AWS CLI, environment variables, or IAM roles)
Installation
| Cursor | VS Code |
|---|---|
Using uvx (Recommended)
Configure the MCP server in your MCP client configuration (e.g., for Claude Desktop, edit the configuration file):
{
"mcpServers": {
"awslabs.ec2-mcp-server": {
"command": "uvx",
"args": ["awslabs.ec2-mcp-server@latest"],
"env": {
"AWS_PROFILE": "default",
"AWS_REGION": "us-west-2",
"FASTMCP_LOG_LEVEL": "INFO",
"ALLOW_WRITE": "true",
"ALLOW_SENSITIVE_DATA": "false"
},
"disabled": false,
"autoApprove": []
}
}
}
Using Docker
First, build the Docker image:
docker build -t awslabs/ec2-mcp-server .
Then configure with Docker in your MCP client:
"awslabs.elasticache-mcp-server": {
"command": "docker",
"args": [
"run",
"--rm",
"--interactive",
"--env",
"FASTMCP_LOG_LEVEL=ERROR",
"awslabs/ec2-mcp-server:latest"
],
"env": {},
"disabled": false,
"autoApprove": []
}
Configuration Options
Environment Variables
AWS_PROFILE: AWS profile name (default: "default")AWS_REGION: AWS region (default: "us-east-1")ALLOW_WRITE: Enable write operations like create/modify/delete (default: "false")ALLOW_SENSITIVE_DATA: Enable access to sensitive resource data (default: "false")FASTMCP_LOG_LEVEL: Logging level - DEBUG, INFO, WARNING, ERROR (default: "INFO")FASTMCP_LOG_FILE: Optional log file path
Security Settings
Important: Write operations are disabled by default for security. Set ALLOW_WRITE=true to enable resource creation/modification/deletion.
Key Pair Storage Configuration
When creating key pairs, you must specify a storage method. Configure these environment variables for S3 KMS encrypted storage:
S3 with KMS Encryption (Recommended - Most Cost-Effective):
S3_KEYPAIR_BUCKET: S3 bucket name for storing encrypted private keys (optional: defaults toec2-mcp-keypairs-{region})S3_KEYPAIR_PREFIX: S3 key prefix for organizing stored keys (default: "private-keys")KMS_KEY_ID: Custom KMS key ID (optional: defaults to aws/s3 default key)
Cost Comparison (1000 key pairs):
- S3 + KMS: ~$0.003/month (99.9% cheaper!)
- Parameter Store: $0-50/month
- Secrets Manager: $400/month
Available Tools
EC2 Instances (9 tools)
list_instances- List EC2 instances with filtering optionsget_instance_details- Get detailed information about a specific instancelaunch_instance- Launch new EC2 instances with full configurationterminate_instance- Terminate EC2 instances permanentlystart_instance- Start stopped instancesstop_instance- Stop running instances (with optional force flag)reboot_instance- Reboot running instancesget_subnet_info- Get subnet information for networkinglist_subnets- List available subnets for instance placement
Security Groups (5 tools)
list_security_groups- List security groups with filteringget_security_group_details- Get detailed security group configurationcreate_security_group- Create new security groups with descriptionsdelete_security_group- Delete security groupsmodify_security_group_rules- Add/remove inbound and outbound rules
Key Pairs (3 tools) - ⚠️ Storage Method Required
list_key_pairs- List available EC2 key pairscreate_key_pair- Requires storage_method parameter (no default)- Must specify one of: "secrets_manager", "s3_encrypted", or "parameter_store"
- Cannot create key pair without explicitly specifying where to store the private key
- For S3 encryption: Uses KMS encryption with default aws/s3 key (configure S3_KEYPAIR_BUCKET for custom bucket)
delete_key_pair- Delete key pairs and associated stored private keys
EBS Volumes (5 tools)
list_volumes- List EBS volumes with status and attachment infocreate_volume- Create new EBS volumes with specified size and typedelete_volume- Delete EBS volumes (must be unattached)attach_volume- Attach volumes to EC2 instancesdetach_volume- Detach volumes from instances
EBS Snapshots (2 tools)
list_snapshots- List EBS snapshots with filteringcreate_snapshot- Create snapshots from EBS volumes
AMIs - Amazon Machine Images (4 tools)
list_amis- List AMIs with ownership and filtering optionsget_popular_amis- Get popular public AMIs (Amazon Linux, Ubuntu, Windows, RHEL)create_image- Create custom AMIs from running instancesderegister_image- Deregister/delete AMIs
VPC & Networking (5 tools)
list_vpcs- List Virtual Private Cloudsget_default_vpc- Get the default VPC for the regionfind_suitable_subnet- Find appropriate subnets for instance placementdelete_vpc- Delete VPCs (advanced operation)list_subnets- List subnets with VPC filtering
Common Workflows
Launch a Web Server
get_popular_amis- Find latest Amazon Linux AMIcreate_key_pair- YOU MUST CHOOSE: storage_method="secrets_manager" OR "s3_encrypted" OR "parameter_store"create_security_groupfor HTTP/SSH accesslaunch_instancewith the AMI, key pair, and security group
Create Custom AMI
list_instances- Find your configured instancestop_instance- Stop for consistent snapshotcreate_image- Create AMI from instancestart_instance- Restart original instance
Volume Management
create_volume- Create additional storageattach_volume- Attach to running instancecreate_snapshot- Backup volume data
Required AWS Permissions
The server requires the following IAM permissions:
{
"Version": "2012-10-17",
"Statement": [
{
"Effect": "Allow",
"Action": [
"ec2:*",
"ssm:GetParameter",
"ssm:PutParameter",
"ssm:DeleteParameter",
"s3:GetObject",
"s3:PutObject",
"s3:DeleteObject",
"secretsmanager:GetSecretValue",
"secretsmanager:CreateSecret",
"secretsmanager:DeleteSecret",
"sts:GetCallerIdentity"
],
"Resource": "*"
}
]
}
For production use, consider implementing more restrictive permissions based on your specific needs.
License
This project is licensed under the Apache License, Version 2.0.
Project details
Download files
Download the file for your platform. If you're not sure which to choose, learn more about installing packages.
Source Distribution
Built Distribution
Filter files by name, interpreter, ABI, and platform.
If you're not sure about the file name format, learn more about wheel file names.
Copy a direct link to the current filters
File details
Details for the file test_awslabs_ec2_mcp_server-0.1.4.tar.gz.
File metadata
- Download URL: test_awslabs_ec2_mcp_server-0.1.4.tar.gz
- Upload date:
- Size: 151.1 kB
- Tags: Source
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/6.1.0 CPython/3.13.2
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
0ef819399118ee67ae551c41e0760253193372e3c887bf98f3d8e2ac7cd86d32
|
|
| MD5 |
278c081baef3ab4846072d485cc5409c
|
|
| BLAKE2b-256 |
97208ef26d0b0102b13e9360bab5dd49cfe5c80a91336e230f66f0967fe4fcbc
|
File details
Details for the file test_awslabs_ec2_mcp_server-0.1.4-py3-none-any.whl.
File metadata
- Download URL: test_awslabs_ec2_mcp_server-0.1.4-py3-none-any.whl
- Upload date:
- Size: 52.7 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/6.1.0 CPython/3.13.2
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
c214614b348218be6daf94504ce7595e111303fef3cb9e0ad11bdf580af720f2
|
|
| MD5 |
b21ad0a7c7f3e4ff8e1134812771699a
|
|
| BLAKE2b-256 |
a8f87eae7c6242bb2d45da3313170aaf1bd427c864d8f84b836a293cdafce4db
|