Create and publish an Amazon Machine Image (AMI) based on Amazon Linux 2023 x86_64 with the latest Node.js LTS for running Node.js web applications.
- Amazon Linux 2023 x86_64 - Latest stable Linux distribution from AWS
- Node.js LTS - Latest Long Term Support version of Node.js
- AWS CLI v2 - Latest AWS Command Line Interface for cloud operations
- Production Ready - Pre-configured with PM2, Forever, and Nodemon
- Web Server Ready - Nginx configured as reverse proxy
- Firewall Configured - Ports 80, 443, 3000, and 8080 open
- Sample Application - Includes a sample Node.js app for testing
- Systemd Integration - Service templates for easy app deployment
- Packer installed
- AWS CLI configured with appropriate credentials
- AWS account with EC2 permissions
git clone https://github.com/anevis/aws-ami-linux-x86_64-nodejs.git
cd aws-ami-linux-x86_64-nodejs
aws configure
./build.sh
Copy the example variables file and customize:
cp variables.pkrvars.hcl.example variables.pkrvars.hcl
Edit variables.pkrvars.hcl
:
region = "us-west-2"
instance_type = "t3.small"
ami_name = "my-custom-nodejs-ami-{{timestamp}}"
ami_description = "My custom Node.js AMI"
# Initialize Packer
packer init aws-ami-nodejs.pkr.hcl
# Validate configuration
packer validate aws-ami-nodejs.pkr.hcl
# Build AMI
packer build aws-ami-nodejs.pkr.hcl
- Node.js LTS - Latest Long Term Support version
- npm - Node Package Manager
- AWS CLI v2 - Latest AWS Command Line Interface
- PM2 - Production process manager
- Forever - Simple CLI tool for continuous running
- Nodemon - Development tool for auto-restarting
- Nginx - Web server and reverse proxy
- Firewalld - Firewall management
/opt/nodejs/ # Node.js applications directory
/opt/nodejs/sample-app/ # Sample application
/etc/nginx/conf.d/ # Nginx configuration
/etc/systemd/system/ # Systemd service templates
/usr/local/bin/nodejs-app-deploy
- Deploy Node.js applications
aws ec2 run-instances \
--image-id ami-xxxxxxxxx \
--instance-type t3.micro \
--key-name your-key-name \
--security-group-ids sg-xxxxxxxxx
- Upload your Node.js application to
/opt/nodejs/your-app/
- Use the helper script:
nodejs-app-deploy your-app /opt/nodejs/your-app
- Your app will be available at
http://your-instance-ip/
# Start your application
sudo systemctl start nodejs-app@your-app
# Enable auto-start on boot
sudo systemctl enable nodejs-app@your-app
# Check status
sudo systemctl status nodejs-app@your-app
Internet β EC2 Security Group β Nginx (Port 80) β Node.js App (Port 3000)
- Nginx handles incoming HTTP requests on port 80
- Reverse proxy forwards requests to Node.js app on port 3000
- Firewall allows HTTP (80), HTTPS (443), and development ports (3000, 8080)
- Systemd manages Node.js application lifecycle
βββ aws-ami-nodejs.pkr.hcl # Main Packer configuration
βββ build.sh # Build script
βββ variables.pkrvars.hcl.example # Variables template
βββ scripts/
β βββ install-nodejs.sh # Node.js installation script
β βββ configure-system.sh # System configuration script
βββ README.md # This file
- Packer not found: Install Packer from packer.io
- AWS credentials: Run
aws configure
or set environment variables - Permissions: Ensure your AWS user has EC2 and IAM permissions
- Region: Make sure your AWS CLI region matches the Packer configuration
- Build logs: Check Packer output during build
- Instance logs:
/var/log/cloud-init-output.log
- Application logs:
journalctl -u nodejs-app@your-app
MIT License - see LICENSE file for details.
- Fork the repository
- Create a feature branch
- Make your changes
- Test the build
- Submit a pull request
For questions and support, please open an issue in the GitHub repository.