Skip to content

anevis/aws-ami-linux-x86_64-nodejs

Folders and files

NameName
Last commit message
Last commit date

Latest commit

Β 

History

6 Commits
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 

Repository files navigation

AWS AMI Linux x86_64 with Node.js by anevis

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.

πŸš€ Features

  • 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

πŸ“‹ Prerequisites

  • Packer installed
  • AWS CLI configured with appropriate credentials
  • AWS account with EC2 permissions

πŸ› οΈ Quick Start

1. Clone the repository

git clone https://github.com/anevis/aws-ami-linux-x86_64-nodejs.git
cd aws-ami-linux-x86_64-nodejs

2. Configure AWS credentials

aws configure

3. Build the AMI

./build.sh

βš™οΈ Customization

Using Variables

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"

Manual Build

# 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

🎯 What's Included

Software Components

  • 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

Directory Structure

/opt/nodejs/              # Node.js applications directory  
/opt/nodejs/sample-app/   # Sample application
/etc/nginx/conf.d/        # Nginx configuration
/etc/systemd/system/      # Systemd service templates

Helper Scripts

  • /usr/local/bin/nodejs-app-deploy - Deploy Node.js applications

πŸš€ Using the AMI

Launch Instance

aws ec2 run-instances \
  --image-id ami-xxxxxxxxx \
  --instance-type t3.micro \
  --key-name your-key-name \
  --security-group-ids sg-xxxxxxxxx

Deploy Your Application

  1. Upload your Node.js application to /opt/nodejs/your-app/
  2. Use the helper script:
nodejs-app-deploy your-app /opt/nodejs/your-app
  1. Your app will be available at http://your-instance-ip/

Manual Service Management

# 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

πŸ—οΈ Architecture

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

πŸ“ File Structure

β”œβ”€β”€ 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

πŸ”§ Troubleshooting

Common Issues

  1. Packer not found: Install Packer from packer.io
  2. AWS credentials: Run aws configure or set environment variables
  3. Permissions: Ensure your AWS user has EC2 and IAM permissions
  4. Region: Make sure your AWS CLI region matches the Packer configuration

Logs

  • Build logs: Check Packer output during build
  • Instance logs: /var/log/cloud-init-output.log
  • Application logs: journalctl -u nodejs-app@your-app

πŸ“ License

MIT License - see LICENSE file for details.

🀝 Contributing

  1. Fork the repository
  2. Create a feature branch
  3. Make your changes
  4. Test the build
  5. Submit a pull request

πŸ“ž Support

For questions and support, please open an issue in the GitHub repository.

About

Create and push an Amazon Machine Image (AMI) to AWS Market place

Resources

License

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published

Contributors 2

  •  
  •