Skip to content

Instantly share code, notes, and snippets.

@chiefmikey
Created February 23, 2022 22:48
Show Gist options
  • Save chiefmikey/0c8d6b9c23a68bd3bb0875cdf6e02ecd to your computer and use it in GitHub Desktop.
Save chiefmikey/0c8d6b9c23a68bd3bb0875cdf6e02ecd to your computer and use it in GitHub Desktop.
AWS EC2 run a script on every instance start
# Select the AWS EC2 instance and change the state to stopped
# Go to Actions -> Instance settings -> Edit user data
# Paste this with your script and save
Content-Type: multipart/mixed; boundary="//"
MIME-Version: 1.0
--//
Content-Type: text/cloud-config; charset="us-ascii"
MIME-Version: 1.0
Content-Transfer-Encoding: 7bit
Content-Disposition: attachment; filename="cloud-config.txt"
#cloud-config
cloud_final_modules:
- [scripts-user, always]
--//
Content-Type: text/x-shellscript; charset="us-ascii"
MIME-Version: 1.0
Content-Transfer-Encoding: 7bit
Content-Disposition: attachment; filename="userdata.txt"
#!/bin/bash
# Your script goes here
--//--
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment