Skip to primary content
Skip to secondary content

Out of the box

Do it.

Out of the box

Main menu

  • Home
  • Categories
    • My Hobbies
    • Transformers
    • Mecha
    • Information Technology
  • 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 einsamsoldat
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

  • The “Body Recomposition” Blueprint: A Guide Forged from Real Data
  • Going beyond vibe coding to use AI as health and gym coaching
  • Use Ventoy to create USB drive multiboot disk for your computer
  • How to subscribe to right issue in Malaysia
  • Quickly installing wazuh into docker environment

Recent Comments

  1. A WordPress Commenter on Hello AWS Hosted Site!
  2. KarMeng on About
  3. Kyle Kho on About
  4. KarMeng on Alter ARX-7 Arbalest Full Metal Panic review
  5. RISMA ANDIANI on Alter ARX-7 Arbalest Full Metal Panic review

Tags

armament articulation ARX-7 ARX7 autobot bandai convoy cybertron Decepticon Deluxe Class Destron diecast Full Metal Panic G1 g1 convoy Generation 1 Generation1 gimmick hasbro hasbro transformers henkei jet jetfire jet fire leader class linux optimus optimus prime prime revenge of the fallen review review summary robot robot mode ROTF takara takaratomy takara tomy transformer Transformers transformers classic transformers hybrid style Transformers Universe Ubuntu Voyager Class

Follow my social media

  • LinkedIn
  • Instagram
  • Pinterest
Privacy Policy Proudly powered by WordPress