Amazon EC2
aws ec2 run-instances
--image-id ami-12345678
--instance-type t3.micro
--user-data file://script.yamlCreates and configures a swap file for systems with limited RAM
#cloud-config
write_files:
- path: /etc/sysctl.d/99-swappiness.conf
content: |
# Reduce swap usage
vm.swappiness=10
vm.vfs_cache_pressure=50
runcmd:
# Create 2GB swap file
- fallocate -l 2G /swapfile
# Set permissions
- chmod 600 /swapfile
# Make swap
- mkswap /swapfile
# Enable swap
- swapon /swapfile
# Add to fstab for persistent mounting
- echo '/swapfile none swap sw 0 0' >> /etc/fstab
# Verify swap is active
- swapon --show
- free -haws ec2 run-instances
--image-id ami-12345678
--instance-type t3.micro
--user-data file://script.yamldoctl compute droplet create
--image ubuntu-22-04-x64
--size s-1vcpu-1gb
--user-data-file script.yaml
my-dropletgcloud compute instances create
my-instance
--metadata-from-file
user-data=script.yaml