Connecting to a private Windows EC2 instance without exposing RDP to the internet

The problem statement Let’s say you have a (Windows or Linux) EC2 instance in a private subnet and want to access it interactively. There are several ways to do this: You could use a bastion host in your public subnet, harden it and limit access to a certain IP range, and then tunnel your SSH or RDP (or any other TCP) traffic through this host using SSH. Alternatively, you could set up a VPN server through which to connect to your instance. ...

February 12, 2024

Terraform: Change EC2 user_data without recreating instance

When you have set up your infrastructure with Terraform and then do any change to the user_data of a EC2 instance, Terraform will detect the change and generally do a force-replacement of the instance. In the planning stage this could look something like this: # aws_instance.web_backend must be replaced -/+ resource "aws_instance" "web_backend" { [...] ~ user_data = "1c4e236bd5dec74fecc99d3a3d57679b9b12a927" -> "f8d9add08d4ead74d44af35452c6070dbfcb1576" # forces replacement + user_data_base64 = (known after apply) [...] So what can you do when you want to make changes to user_data but don’t want to destroy your instance and create a new one? ...

June 9, 2022

Database backups via mysqldump: from MariaDB container to S3

For a little side project I wanted an easy way to perform regular backups of a MariaDB database and upload the resultant dump gzipped to S3. Here are the steps to make this happen. The setup Docker container running MariaDB Docker engine running on a AWS EC2 instance An S3 bucket as the destination for the dumps Writing the backup script We begin with writing our shell script, backup.sh, which we will later execute in regular intervals from our host: ...

May 13, 2022

Resolving import issues when deploying Python code to AWS Lambda

AWS Lambda is Amazon’s “serverless” compute platform that basically lets you run code without thinking (too much) of servers. I used Lambda in the past, though only in the Node.js environment. Wanting to deploy my first Python function, I ran into a couple of problems. Deployment scenarios There are two deployment scenarios: Simple scenario Advanced scenario The simple scenario applies to you when your function code only requires the AWS SDK library (Boto 3) and no other external resources. Just use Lambda’s inline code editor and you are good to go. No need to read the rest of this article :-) ...

January 27, 2017