Command Line creation of DNS ‘A’ Record in AWS Route53

If you need to add a new record to a Route53 hosted Zone it can be clunky to log in, browse to the right place and manually add your record each time.

If you’re already using some elements of aws or eb command line functionality then this might just be a small step for you which simplifies a currently manual process.

The aws route53 tools are far more powerful than I will cover here. You could add multiple records in a single request. You could updated existing records, or even toggle certain records.

Hopefully this article and the links are enough to get you on your way.

Now the guides generally tell you to create and use a .json file to pull in your config when running the command line, but where the command is simple and you might want to document it, or share it, it’s easier if the whole thing is a single line. If you want to use a .json file then check out the AWS docs for that.

My initial need was to add a single new subdomain to a domain which has many records. Rather than log in and add the record each time, now it’s part of a flow of other command line requests and means less context switching. Opening a browser for any reason can lead to distraction.

I am however not adding a standard ‘A’ record. I’m actually pointing to an Application Load Balancer so I’ll show you the differences for that below.

The first thing you’ll need to do is confirm you have aws command line tools set up and with permissions for the account you’ll be making changes for. Confirmed? Continue…

aws route53 list-hosted-zones

Find the relevent zone in the list and make a note of the final part of the Id from the last forward slash.

Now we’re going to CREATE in our examples but you can also DELETE or UPSERT (update if exists, insert otherwise).

You can also CREATE all sorts of other records, but we’ll stick to ‘A’ for now as it’s a pretty popular record to add.

Take the following and replace the hosted zone id with the code part taken from above after the forward slash. Replace the domain name with yours, replace the subdomain with the one you want to add.

aws route53 change-resource-record-sets --hosted-zone-id BD55*****RS2 --change-batch '{"Changes": [{"Action": "CREATE","ResourceRecordSet": {"Name": "","Type":"A","ResourceRecords": [{"Value": ""}]}]}'

And then run it. You can optionally add a comment, TTL and other details. See the docs for that.

Hopefully if you got the zone id right and the details in the right place, you’ll now have a new record in your route53. You can check with:

aws route53 list-resource-record-sets --hosted-zone-id BD55*****RS2


If you want to point to an Alias—for example to point to a load balancer—you’ll first need to confirm the details of the loadbalancer to point to.

Here we’re specifically looking for the ‘hosted zone id’ and the ‘DNS Name’.

aws elbv2 describe-load-balancers --region [The Region]

… switch out the region above first. You should then be shown a list of your load balancers. Match the one you need to point to by its code. I actually looked at my existing DNS records to find that using the list-resource-record-sets method above. Then copy the Hosted Zone ID and the DNS Name for it somewhere safe.

The code when an alias is involved contains little more information. In the following you’ll need to replace…

  • the hosted-zone-id with that of your domain
  • the HostedZoneId with that of your load balancer
  • the domain Name
  • the DNSName of your load balancer
  • the true / false value for EvaluateTargetHealth
aws route53 change-resource-record-sets --hosted-zone-id BD55*****RS2 --change-batch '{"Changes": [{"Action": "CREATE","ResourceRecordSet":{"Name": "","Type": "A","AliasTarget":{"HostedZoneId":"AC22*****UE7","DNSName": "dualstack.awseb-awseb-Lptg*****fDJ-203*****","EvaluateTargetHealth": false}}}]}'

Run the above and you’ll be shown basic details about the new record. Again you can run the list-resource-record-sets line above to confirm it’s been created.

Hopefully that’s enough to get you started and you can move on to other options using the official AWS docs. You can also put batches of changes into a .json file if you’d like to CREATE multiple records at a time.

Update Lightsail PHP Version via Snapshot

I haven’t had a chance to try this yet, but it could be a much quicker option that the previous guide which focused more on WordPress and required a full export and import.

So if you give this a go, let me know how you get on and I’ll update the other article accordingly.


Just to be very clear, I haven’t yet run through this process in competion myself and there may be steps missing from this guide which will help with things like IP addresses and SSL certificates. Use it with care and let me know how you get on.

Confirm a new Lightsail instance will be created with a high enough version of PHP

Before you get started, it’s worth you confirming that a new AWS Lightsail instance can be created with a PHP version high enough to fulfil your requirements or to resolve any warmomg message displayed in WordPress. The Lightsail service doesn’t immediately start offering new PHP versions when they are made available, and so you may need to wait on the Lightsail PHP versions on offer being updated before you continue with this process.

Create a snapshot

The first step is to manually create a snapshot of your current Lightsail instance. You could do this from an ‘Automatic’ snapshot too, but they probably happen in the middle of the night if you have them enabled, and so might be out of date.

You do that from the lightsail dashboard by clicking an instance name to view it’s own screen then click the snapshots tab, then under the ‘Manual snapshots’ title click ‘+ Create snapshot’, and ‘Create’.

You’ll then see a spinning progress icon and ‘snapshotting’ while that process completes. Once done the panel will switch to show the date and time.

Use the snapshot to create a new instance

On the new snapshot’s panel, and indeed on the panels of all snapshots there is an options dots icon on the right side.

Clicking the three vertical dots icon on the right shows ‘Create new instance’ as the first option in a dropdown. Click that.

Lightsail is clever enough to know the type of instance you need at this point, so you don’t see that option, and if you’re getting close to your available storage, or the applications run slow, this is your chance to increase the instance size.

Lightsail also repopulates any tags your existing instance has.

The instance name will need to be unique. Here you probably want to either increment your instance name, so WordPress-1, 2, 3 etc or you could use the php version it’s using, or even the date your created it, for example WordPress-2021-04-16.

Once you’re happy, click ‘Create instance’.

You’ll then be redirected back to the dashboard and shown the new instance in ‘Pending’ status.

IP addresses

If you’re not using a static IP then you’re going to have to point any domain name DNS to the new IP address, but before you do so I would recommend adding a static IP to the new instance first so you can take advantage of the steps below in the future.

Got a static IP on your previous instance? The new instance will not yet have a static IP, but that’s a good thing. You can reassign the IP of the previous instance to the new instance and save having to change anything related to domain name DNS etc.

To do this, check the Static IP name of your previous instance by clicking the networking tab from it’s own page.

Head back to the Lightsail dashboard via the ‘Home’ link in the header and click the networking tab. Find the static IP name again and click it. Then on the IP’s own page you can ‘Detach’ and attach it to the new instance.


Once again, I haven’t been through all this yet to confirm any missing steps and I haven’t confirmed what happens with SSL certificates when you do this. I would love to hear how you get on.

Once I’ve run through this or heard from people who have, I’ll add some screenshots to further support.

Creating a scheduled Lambda or Lambda Cron

This guide revolves around a basic twitter bot implementation which posts a single tweet to the same twitter account every 6 hours.

It allows any Node script (or other if you fancy doing the work to get PHP/Python etc running) to be triggered on any schedule, from every minute to once every year.

Several steps are involved in getting this all up and running:

  • Get our Twitter auth details
  • Write our bot code
  • Create the Lambda in AWS Console
  • Add Environmental variables to keep our security details safe
  • Test our Lambda function
  • Set up a Cloudwatch trigger to act as the scheduler
  • Confirm the schedule is running as expected

Get our Twitter auth details

Open and consider which account you’re going to post tweets to.

You may need to sign up and verify your account. Do all that, or just login.

Once you’re in create a new app. Click to create or view keys / access details and ensure you have an App Token, App Secret, User Secret and User Token. So four hashes in total. Two tokens and two secrets.

Also check that your user details have read and write access so we can post tweet updates.

Continue reading “Creating a scheduled Lambda or Lambda Cron”

Updating PHP on an AWS Lightsail WordPress Stack

Before you get started, there is probably an easier way. I haven’t tested it yet, but if you’re brave then you could do so and let me know how you get on. See Update Lightsail PHP version via snapshot for all the details.

Updated 27th September 2020 to consider restart of all services where restarting just apache isn’t enough, and also to share choice when it comes to import first vs SSL first as you may lose permalinks. Thanks to Peter and Simon in the comments.

Updated 25th January 2021 to add an initial paragraph clarifying that you can’t ‘choose’ a PHP version on Lightsail and to further clarify that you must first check which version of PHP a new AWS Lightsail instance will be built with to confirm it will resolve the message being displayed in WordPress.

NB: If you’re hoping for a way to click ‘update php’ or ‘use X version of PHP’ in Lightsail, it doesn’t (at time of writing) exist. This guidance will walk you though creating a new Lightsail instance with a newer version of PHP installed and moving everything over to it.

The AWS Lightsail service is great. Click a few buttons and you have a powerful VPS with WordPress up and running for only a few dollars a month. The Bitnami integration allows you to choose from a whole set of Stacks to include upon setup. The LAMP option allows a competent PHP developer to run almost anything on Lightsail.

But after a while running the Lightsail VPS the setup is going to get stale, and because Bitnami bundles everything up, it’s not recommended to go poking around with only a few parts of it.

That’s the challenge I was faced with. Logging into the WordPress admin console a message is displayed which is telling me WordPress would prefer a newer version of PHP please. My version was old and not receiving security updates.

I read a fair bit about my options, but after looking at the choices I decided the best thing was to do an export and import onto a new Lightsail instance.

Continue reading “Updating PHP on an AWS Lightsail WordPress Stack”

Quick and dirty export of AWS Elastic Beanstalk Environmental Variables

A very quick and dirty way to export key and value pairs from web console of elastic beanstalk environments config page.

While viewing the elastic beanstalk config page containing the variable inputs paste the following into your browser console.

var strs = [], inputs = $('.properties-table input');
$.each(inputs, function(key, input){
    strs.push(inputs[(key-1)].value + ' = ' + inputs[key].value);