Postingan

Menampilkan postingan dengan label AWS

📘 How to Send Apache + ModSecurity Logs to AWS CloudWatch Logs on EC2

In this guide, you'll learn how to forward ModSecurity logs from Apache to AWS CloudWatch Logs using the CloudWatch Agent on an EC2 instance with an IAM Role , and ensure it runs reliably using systemd . ✅ Prerequisites An EC2 instance (Ubuntu/Debian) Apache2 and ModSecurity installed Instance has an IAM Role attached with permission: CloudWatchAgentServerPolicy or: { "Effect": "Allow", "Action": [ "logs:CreateLogGroup", "logs:CreateLogStream", "logs:PutLogEvents", "logs:DescribeLogStreams" ], "Resource": "*" } ⚙️ Step 1: Install the CloudWatch Agent cd /opt curl -O https://s3.amazonaws.com/amazoncloudwatch-agent/ubuntu/amd64/latest/amazon-cloudwatch-agent.deb sudo dpkg -i amazon-cloudwatch-agent.deb 🛠️ Step 2: Create the Agent Configuration File Save this file as /opt/cloudwatch-config.json : { "logs": { "logs_colle...

🔐 How to Connect to Amazon RDS MySQL with IAM Authentication

Amazon RDS supports IAM-based authentication for MySQL. This means you no longer need to hardcode passwords in your code or scripts — instead, you generate a temporary IAM token securely. But setting it up can get tricky. In this guide, you’ll learn: ✅ How to configure IAM auth for MySQL ✅ How to grant user access ✅ How to import a .sql file securely ✅ How to fix common errors like ERROR 1045 and plugin not enabled ✅ Step 1: Enable IAM DB Authentication on Your RDS Instance Go to RDS Console > Your DB > Modify Scroll to "IAM DB Authentication" Set to ✅ Enabled Apply changes ( Apply immediately ) This allows your MySQL instance to accept login using IAM tokens. ✅ Step 2: Create a MySQL User with IAM Plugin Connect using the master user : mysql -h <rds-endpoint> -u <master-user> -p Create a new user (e.g. wordpress_db_user ) with IAM support: CREATE USER 'wordpress_db_user'@'%' IDENTIFIED WITH AWSAuthenticationPl...

How to create a VM/Instance in AWS via CLI

Install AWS CLI curl "https://d1vvhvl2y92vvt.cloudfront.net/awscli-exe-linux-x86_64.zip" -o "awscliv2.zip" unzip awscliv2.zip sudo ./aws/install https://docs.aws.amazon.com/cli/latest/userguide/install-cliv2-linux-mac.html Configure AWS CLI aws configure https://docs.aws.amazon.com/cli/latest/userguide/cli-chap-configure.html Create a key-pair aws ec2  create-key-pair --key-name MyVMKey The output is an ASCII version of the private key and key fingerprint. You need to save the key to a file. https://docs.aws.amazon.com/AWSEC2/latest/UserGuide/ec2-key-pairs.html Create a security group aws ec2 create-security-group --group-name MySecurityGroup --description "My security group" Configure security group to allow SSH traffic aws ec2 authorize-security-group-ingress --group-name MySecurityGroup --protocol tcp --port 22 --cidr 0.0.0.0/0 Create an instance aws ec2 run-instances --image-id ami-061eb2b23f9f8839c --key-name Nasohi-VM...