AgentSkillsCN

eb-docs

当用户询问关于Elastic Beanstalk的文档、最佳实践、“我该如何…”、“Beanstalk文档”、“EB文档”、“Beanstalk帮助”、平台特定指南,或需要参考信息时,应使用此技能。若要进行EB CLI操作,请使用专用技能(部署、状态、日志、配置、故障排除、环境、应用、维护)。若要管理AWS基础设施(SSL、域名、密钥、数据库、安全、监控、成本),请使用eb-infra技能。

SKILL.md
--- frontmatter
name: eb-docs
description: This skill should be used when the user asks about Elastic Beanstalk documentation, best practices, "how do I", "beanstalk docs", "eb documentation", "beanstalk help", platform-specific guidance, or needs reference information. For EB CLI operations use the dedicated skills (deploy, status, logs, config, troubleshoot, environment, app, maintenance). For AWS infrastructure (SSL, domains, secrets, database, security, monitoring, costs) use the eb-infra skill.

AWS Elastic Beanstalk Documentation (EB CLI)

Provide documentation, best practices, and reference information for Elastic Beanstalk using the EB CLI.

When to Use

  • User asks "how do I..." regarding Elastic Beanstalk
  • User wants best practices or recommendations
  • User needs platform-specific guidance
  • User asks about EB concepts or architecture

EB CLI Quick Reference

Installation

bash
pip install awsebcli
# or
brew install awsebcli

Verify Installation

bash
eb --version

Initialize Project

bash
eb init

Core Commands

CommandDescription
eb initInitialize EB project
eb createCreate new environment
eb deployDeploy application
eb statusShow environment status
eb healthShow health status
eb logsGet logs
eb configEdit configuration
eb terminateTerminate environment
eb listList environments
eb useSet default environment
eb openOpen in browser
eb eventsShow recent events
eb sshSSH to instance
eb scaleScale instances
eb setenvSet environment variables
eb printenvShow environment variables
eb upgradeUpgrade platform
eb cloneClone environment
eb swapSwap environment URLs
eb abortAbort in-progress update
eb restoreRestore terminated env
eb appversionManage app versions
eb platformPlatform operations
eb consoleOpen AWS Console
eb tagsManage environment tags
eb restartRestart app server
eb codesourceConfigure CodeCommit integration
eb localRun Docker app locally
eb labsExperimental features
eb migrateMigrate IIS apps to EB (Windows)

AWS Documentation Links

General

Platforms

Platform Best Practices

Node.js

code
Project Structure:
├── package.json          # Required: dependencies & scripts
├── .npmrc                # Optional: npm configuration
├── Procfile              # Optional: custom start command
├── .ebignore             # Optional: files to exclude
└── .ebextensions/        # Optional: EB configuration

Key Settings:
- NODE_ENV=production
- npm start should work
- Listen on process.env.PORT (default: 8080)

Python

code
Project Structure:
├── requirements.txt      # Required: pip dependencies
├── application.py        # WSGI application
├── Procfile             # Optional: custom command
├── .ebignore            # Optional: files to exclude
└── .ebextensions/       # Optional: EB configuration

Key Settings:
- WSGIPath: application:application
- NumProcesses, NumThreads for scaling

Java

code
Project Structure:
├── target/app.war        # WAR file (Tomcat)
├── target/app.jar        # JAR file (standalone)
├── Procfile             # For JAR: web: java -jar app.jar
└── .ebextensions/       # Optional: EB configuration

Key Settings:
- JVM options via JAVA_OPTS
- Heap size configuration

Docker

code
Project Structure:
├── Dockerfile            # Required for single container
├── docker-compose.yml    # For multi-container
├── .dockerignore        # Exclude files from build
└── .ebextensions/       # Optional: EB configuration

Key Settings:
- Expose port 80 or configure proxy
- Use multi-stage builds for smaller images

.platform/ Directory (AL2 and AL2023)

On Amazon Linux 2 and AL2023, use .platform/ for hooks and reverse proxy customization:

code
.platform/
├── hooks/                    # Run during deployments & platform updates
│   ├── prebuild/             # Before app build (install dependencies)
│   ├── predeploy/            # After build, before app deploy
│   └── postdeploy/           # After app deploy completes
├── confighooks/              # Run only on configuration changes
│   ├── prebuild/
│   ├── predeploy/
│   └── postdeploy/
└── nginx/
    ├── conf.d/               # Additional nginx config (*.conf)
    └── nginx.conf            # Full nginx config (replaces default)

Hook scripts must be executable (chmod +x). They run as root.

Platform Hook Example

bash
# .platform/hooks/postdeploy/01_restart_service.sh
#!/bin/bash
systemctl restart my-service

Nginx Customization

code
# .platform/nginx/conf.d/client_max_body.conf
client_max_body_size 50M;

Note: .ebextensions/ still works on AL2/AL2023 for option_settings and resources, but prefer .platform/hooks/ over .ebextensions/ commands/container_commands for lifecycle scripts.

.ebextensions Examples

Environment Variables

yaml
# .ebextensions/env.config
option_settings:
  aws:elasticbeanstalk:application:environment:
    NODE_ENV: production
    LOG_LEVEL: info

Packages

yaml
# .ebextensions/packages.config
packages:
  yum:
    gcc: []
    make: []

Commands

yaml
# .ebextensions/commands.config
commands:
  01_create_dir:
    command: mkdir -p /var/app/logs
    ignoreErrors: true

Files

yaml
# .ebextensions/files.config
files:
  "/etc/nginx/conf.d/proxy.conf":
    mode: "000644"
    owner: root
    group: root
    content: |
      client_max_body_size 20M;

.ebignore File

Create .ebignore to exclude files from deployment:

code
# Dependencies
node_modules/
.venv/
__pycache__/

# Build artifacts
dist/
build/
*.pyc

# Local config
.env
.env.local

# IDE
.idea/
.vscode/

# Git
.git/

Experimental & Specialized Commands

eb labs

Experimental features that may change or be removed in future versions:

bash
eb labs --help    # List available lab commands

Warning: Do not rely on eb labs commands for production workflows.

eb migrate (Windows IIS)

Migrates IIS sites from Windows servers to Elastic Beanstalk:

bash
eb migrate --interactive                       # Interactive migration
eb migrate --sites "Default Web Site" --archive-only  # Archive without deploy
eb migrate explore --verbose                   # List available IIS sites
eb migrate cleanup                             # Clean up migration artifacts

Requires IIS 7.0+, Web Deploy 3.6+, and admin privileges. Windows only.

Security Best Practices

Environment Variables

  • Never commit secrets to source control
  • Use AWS Secrets Manager for sensitive values
  • Use eb setenv for configuration
  • Rotate credentials regularly

IAM

  • Use least-privilege instance profiles
  • Separate roles for different environments
  • Enable MFA for console access

Network

  • Use VPC with private subnets for instances
  • Configure security groups restrictively
  • Enable HTTPS with SSL certificate

Troubleshooting Guide

Common Issues

"Environment health has transitioned from Ok to Severe"

bash
eb health    # Check health details
eb logs      # View application logs
eb events    # Check recent events

"Deployment failed"

bash
eb events    # Check deployment errors
eb logs --all  # Get detailed logs

"502 Bad Gateway"

  1. App not listening on correct port
  2. App crashed on startup
  3. Health check failing

"High latency warnings"

bash
eb health --refresh  # Monitor metrics
eb scale 3           # Add more instances

Presenting Documentation

When providing documentation:

  1. Give direct answers first
  2. Include relevant EB CLI commands
  3. Link to official docs for more detail
  4. Provide context for best practices

Example:

code
To set environment variables in Elastic Beanstalk:

1. Via EB CLI (recommended):
   eb setenv NODE_ENV=production API_KEY=secret

2. Via .ebextensions (committed to repo):
   # .ebextensions/env.config
   option_settings:
     aws:elasticbeanstalk:application:environment:
       NODE_ENV: production

3. View current variables:
   eb printenv

Best Practice: Use Secrets Manager for sensitive values.

See: https://docs.aws.amazon.com/elasticbeanstalk/latest/dg/environments-cfg-softwaresettings.html

Composability

  • Deploy code: Use deploy skill
  • Check status & health: Use status skill
  • View logs: Use logs skill
  • Change configuration: Use config skill
  • Troubleshoot issues: Use troubleshoot skill
  • Manage environments: Use environment skill
  • Manage applications: Use app skill
  • Platform updates: Use maintenance skill
  • AWS infrastructure (SSL, domains, secrets, DB, security, monitoring, costs): Use eb-infra skill

Additional Resources

For detailed reference information, see the shared reference files: