forked from slimm609/mock-instance-profile
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathmock-instance-profile
More file actions
executable file
·42 lines (35 loc) · 1.29 KB
/
mock-instance-profile
File metadata and controls
executable file
·42 lines (35 loc) · 1.29 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
#!/usr/bin/env bash
# run ec2-metadata-mock with a generated config on the local system
CURRENT_DIR="$(cd "$(dirname "${BASH_SOURCE[0]}")" && pwd)"
# get the role ARN as input.
role="${1}"
# validate that it is a proper role to attempt to assume
if ! (echo "${role}" | grep -Eq "^arn:(aws|aws-us-gov|aws-cn):iam::\d{12}:role\/[-_a-zA-Z0-9]+$"); then
echo "Error: no role or invalid role provided."
exit 1
fi
# ensure that we have the mock binary installed and
# available in the user path.
if ! command -v ec2-metadata-mock > /dev/null 2>&1; then
echo "Error: ec2-metadata-mock binary not found in PATH."
exit 1
fi
# check if we are already root
#needSudo=""
#if [[ $(id -u) != 0 ]]; then
# needSudo="sudo"
#fi
# The virtual interface can just be created over and over
# without any issues so we don't need to check if it already exists
#if [[ $(uname -s) == "Linux" ]]; then
# "${needSudo}" ifconfig lo:0 169.254.169.254 netmask 255.255.255.255
#elif [[ $(uname -s) == "Darwin" ]]; then
# "${needSudo}" ifconfig lo0 alias 169.254.169.254
#else
# echo "Could not determine OS... Exiting"
# exit 1
#fi
# generate config
[[ -d ${HOME}/.aws/ ]] || mkdir -p "${HOME}"/.aws/
python3 "${CURRENT_DIR}"/generate_mock_config.py --roleArn "${role}"
ec2-metadata-mock -p 80 -c "${HOME}"/.aws/mock_config.json