This is a simple shell script to use as 'User Data' when launching an Amazon Linux AMI based EC2 instance serving as a Splunk quick Lab.
It will install Splunk and perform a few configuration steps so that Splunk is accessible straight away without any of the actions usually required with a fresh install.
It will also download Splunk Apps and Add-ons either from Splunkbase or from a provided S3 bucket and install them.
The goal is to set up a throwable Splunk instance for lab purposes without any dialog box to interfere.
Set password
variable
# Provide the Splunk admin password you want to set
export password="<password>"
- Set
download_splunkbase
variable to true
# Set to true if you need to download Splunk Apps & Add-ons from Splunkbase
readonly download_splunkbase="false"
- Set Splunk.com credentials
# Provide Splunk.com credentials (could be a junk account)
readonly splunk_com_login="<login>"
readonly splunk_com_password="<password>"
- Provide the ID and version of each App or Add-on you want to download from Splunkbase
# Provide the id and version of each App or Add-on you want to download from Splunkbase
readonly splunkbase_apps=("<app_id> <app_version>" "<app_id> <app_version>")
Note: Get an App or Add-on's ID from its Splunkase URL:
https://splunkbase.splunk.com/app/<app_id>/
.
- Set
retrieve_s3_data
variable to true
# Set to true if you need to retrieve Splunk Apps & Add-ons for an S3 bucket?
readonly retrieve_s3_data="true"
- Set
s3_bucket
variable to the name of your S3 bucket
# Provide the name of the bucket you want to retrieve Splunk Apps and Add-ons from
readonly s3_bucket="<s3_bucket>"
Launch an Amazon Linux 2 AMI based EC2.
Quick steps summary
- Launch instance - Pick an 'Amazon Linux 2' AMI
- [Optional] Configure instance details - Specify IAM role if you are retrieving data from S3
- Configure instance details - Copy script in User data field
- [Optional] Add tags
- Configure Security Group - Assign the Security Group allowing HTTP & SSH
- Launch - Pick the right key pair
When your EC2 instance is launched, access Splunk from your browser
http://<EC2 Public IP | Public DNS>
Note that Splunk runs as ec2-user
.
The script configures Splunk to monitor the output of the User Data script so it can be explored from Splunk if needed:
index="_internal" sourcetype="aws:cloud-init" | reverse
Splunk is configured to start at boot time. Hence, whenever you start your instance, Splunk starts.
Script uses Tyler James Frederic's splunkbase-download project