Here is an example of a simple AWS Bash script that uses the AWS CLI to create an EC2 instance:
#!/bin/bash # Set AWS region export AWS_REGION=us-west-2 # Create EC2 instance aws ec2 run-instances \ --image-id ami-0c94855ba95c71c99 \ --instance-type t2.micro \ --key-name MyKeyPair \ --security-group-ids sg-01234567890abcdef0 \ --subnet-id subnet-01234567890abcdef0
This script first sets the AWS region to us-west-2 using the export command. It then uses the aws ec2 run-instances command to create an EC2 instance using the specified Amazon Machine Image (AMI), instance type, key pair, security group, and subnet.
You can also use this script to automate tasks such as starting and stopping instances, creating and deleting S3 buckets, and creating and deleting RDS databases. Additionally, you can use scripting to create alarms and notifications, deploy or update code, or automate backups and disaster recovery.
You can also use some pre-built scripts provided by AWS like aws-scripts-mon, aws-shell and more which can be used to automate some repetitive tasks.