Skip to primary content
Skip to secondary content

Out of the box

Do it

Out of the box

Main menu

  • Home
  • Categories
    • My Hobbies
    • Information Technology
    • Announcements
  • Lab
    • Sanubari WP Offline
      • How To Use Sanubari WP Offline
      • Privacy Policy
  • About
  • Privacy Policy

Tag Archives: metadata

Using AWS metadata to manage and automate tasks in AWS EC2 or AWS Lightsail

Posted on 2024-12-02 by Kar Meng Chow
Reply

This post is based on reference to Use instance metadata to manage your EC2 instance – Amazon Elastic Compute Cloud

Metadata is a powerful tool for AWS users. It allows users to make query of data describing EC2 instances, and making a self reference API call.

By default any linux AMI will have curl build in, hence using of metadata will be simplified.

One of the best test case is automating input into shell script that will requires a lot of user prompt is automating or at least make configuration of setting up openvpn using AWS Lightsail easier.

!#/bin/bash
sudo chmod 777 ./openvpn-install.sh
sudo ./openvpn-install.sh << INPUT


y
1
1
11
n
n

client
1

INPUT
sudo cp /root/client.ovpn /home/ubuntu
sudo chmod 777 /home/ubuntu/client.ovpn

Above shell script will cause the openvpn-install.sh to fail in AWS, as the script does not provide public and local ip of the instance.

Below script are including the AWS Metadata

!#/bin/bash
TOKEN=`curl -X PUT "http://169.254.169.254/latest/api/token" -H "X-aws-ec2-metadata-token-ttl-seconds: 21600"`
PUBLICIP=`curl -X GET "http://169.254.169.254/latest/meta-data/public-ipv4" -H "X-aws-ec2-metadata-token: $TOKEN"`
LOCALIP=`curl -X GET "http://169.254.169.254/latest/meta-data/local-ipv4" -H "X-aws-ec2-metadata-token: $TOKEN"`
sudo chmod 777 ./openvpn-install.sh
sudo ./openvpn-install.sh << INPUT
$LOCALIP
$PUBLICIP
y
1
1
11
n
n

client
1

INPUT
sudo cp /root/client.ovpn /home/ubuntu
sudo chmod 777 /home/ubuntu/client.ovpn

By adding the metadata the ovpn file will be populated with correct IP.

AWS Metadata allow automation to be made simpler by running scripts that requires self-reference metadata to configure newly booted up EC2 instance(s).

Posted in Amazon Web Service, Information Technology, linux, Programming, Ubuntu | Tagged amazon lightsail, automation, EC2, lightsail, metadata | Leave a reply

Recent Posts

  • Turning the Raspberry Pi 5 + 3.5″ LCD into a Portable OTS Cyberdeck
  • Adding a 3.5″ LCD to Raspberry PI 5
  • Finalizing assembly of 3.5 Inch LCD onto Raspberry Pi 5
  • Sneak Peak Of CyberDeck Components Can be Bought OTS
  • Unboxing Pose+ Metal Series 1/28 AFC-01H Legioss Eta

Recent Comments

  1. DINDA AULIA AZZAHRA PUTRI PURWANTO on Using the ESP32 ESP32S Universal Purple Expansion Board module compatible with 38 pins ESP32 development board
  2. DINDA AULIA AZZAHRA PUTRI PURWANTO on programming esp32-wrover with DHT22 (AM2302) humidity and temperature sensor
  3. Kar Meng Chow on programming esp32-wrover with DHT22 (AM2302) humidity and temperature sensor
  4. DINDA AULIA AZZAHRA PUTRI PURWANTO on programming esp32-wrover with DHT22 (AM2302) humidity and temperature sensor
  5. A WordPress Commenter on Moving to new AWS instance completed

Archives

  • November 2026
  • July 2026
  • June 2026
  • May 2026
  • February 2026
  • October 2025
  • August 2025
  • July 2025
  • April 2025
  • March 2025
  • February 2025
  • January 2025
  • December 2024
  • November 2024
  • June 2024
  • May 2024
  • April 2024
  • March 2024
  • February 2024
  • January 2024
  • December 2023
  • November 2023
  • October 2023
  • August 2023
  • July 2015
  • June 2014
  • December 2013
  • September 2013
  • July 2013
  • June 2013
  • May 2013
  • August 2011
  • July 2010
  • March 2010
  • October 2009
  • September 2009
  • August 2009
  • July 2009
  • June 2009
  • May 2009
  • April 2009
  • March 2009
  • February 2009
  • January 2008
  • December 2007
  • August 2007
  • April 2007
  • March 2007

Categories

  • Amazon Web Service
  • Announcements
  • Azure
  • cpanel
  • Database
  • email
  • Full Metal Panic!
  • General
  • gundam
  • Halo
  • Hardware
  • Information Technology
  • linux
  • Mecha
  • My Hobbies
  • nature
  • Network
  • Personal
  • PHP
  • Programming
  • Ruby
  • Security
  • Social Event
  • Transformers
  • Ubuntu
  • Voltes V
  • Windows
Proudly powered by WordPress