forked from floodfx/aws-tools
-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathaws-tools-env.sh
125 lines (105 loc) · 4.26 KB
/
aws-tools-env.sh
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
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
#!/bin/bash
script_path=${BASH_SOURCE:-$0}
# If this script isn't referenced by its full path, prepend the working directory
if [ "`echo $script_path|cut -b1`" == "/" ]; then
dir=$(dirname "$script_path")
else
dir=$(pwd)/$(dirname "$script_path")
fi
# define homes of all CLI tools
export AWS_TOOLS_HOME=$dir
export EC2_AMITOOL_HOME=$dir/ami-tools/ec2-ami-tools-1.5.7
export AWS_AUTO_SCALING_HOME=$dir/autoscaling/AutoScaling-1.0.61.6
export AWS_CLOUDFORMATION_HOME=$dir/cloudformation/AWSCloudFormation-1.0.11
export CS_HOME=$dir/cloudsearch/cloud-search-tools-1.0.0.1-2012.03.05
export AWS_CLOUDWATCH_HOME=$dir/cloudwatch/CloudWatch-1.0.13.4
export EC2_HOME=$dir/ec2/ec2-api-tools-1.7.5.1
export AWS_ELASTICACHE_HOME=$dir/elasticcache/AmazonElastiCacheCli-1.6.001
export AWS_ELB_HOME=$dir/elb/ElasticLoadBalancing-1.0.35.0
export AWS_EMR_HOME=$dir/emr/elastic-mapreduce-ruby-20130708
## NOTE: above works w/ ruby 1.8.7, but fails on osx 10.9.3 / ruby 2.0.0p451; this version works:
# export AWS_EMR_HOME=$dir/emr/elastic-mapreduce-ruby-20131216
export AWS_IAM_HOME=$dir/iam/IAMCli-1.5.0
export AWS_RDS_HOME=$dir/rds/RDSCli-1.10.003
export AWS_SNS_HOME=$dir/sns/SimpleNotificationServiceCli-1.0.3.0
# add executables to the PATH
export PATH=$PATH:$EC2_AMITOOL_HOME/bin
export PATH=$PATH:$AWS_AUTO_SCALING_HOME/bin
export PATH=$PATH:$AWS_CLOUDFORMATION_HOME/bin
export PATH=$PATH:$CS_HOME/bin
export PATH=$PATH:$AWS_CLOUDWATCH_HOME/bin
export PATH=$PATH:$EC2_HOME/bin
export PATH=$PATH:$AWS_ELASTICACHE_HOME/bin
export PATH=$PATH:$AWS_ELB_HOME/bin
export PATH=$PATH:$AWS_EMR_HOME
export PATH=$PATH:$AWS_IAM_HOME/bin
export PATH=$PATH:$AWS_RDS_HOME/bin
export PATH=$PATH:$AWS_SNS_HOME/bin
if [ -z "$AWS_ACCESS_KEY_ID" ]; then
echo "WARNING: AWS_ACCESS_KEY_ID must be set before running $script_path" >&2
fi
if [ -z "$AWS_SECRET_ACCESS_KEY" ]; then
echo "WARNING: AWS_SECRET_ACCESS_KEY must be set before running $script_path" >&2
fi
if [ -z "$EC2_PRIVATE_KEY" ]; then
echo "WARNING: EC2_PRIVATE_KEY must be set before running ec2-* commands" >&2
fi
if [ -z "$EC2_CERT" ]; then
echo "WARNING: EC2_CERT must be set before running ec2-* commands" >&2
fi
if [ -z "$AWS_ACCESS_KEY_ID" ]; then
echo "AWS_ACCESS_KEY_ID was not set. Credentials will only be available via instance-profile. Exiting..." >&2
exit
fi
# developer credential set up...
if [ -z "$AWS_CREDENTIAL_FILE" ]; then
CRED_FILE=~/.aws_credentials
else
CRED_FILE=$AWS_CREDENTIAL_FILE
fi
if [ -f $CRED_FILE ]; then
# make sure credentials are current
TF=`mktemp -t cred.XXX`
echo "AWSAccessKeyId=${AWS_ACCESS_KEY_ID}" > $TF
echo "AWSSecretKey=${AWS_SECRET_ACCESS_KEY}" >> $TF
# overwrite if different and warn
cmp --quiet $CRED_FILE $TF || {
echo "WARNING: AWS_CREDENTIAL_FILE did not contain the currently set AWS_ACCESS_KEY_ID and/or AWS_SECRET_ACCESS_KEY. Updating $CRED_FILE with currently set keys." >&2
cp $TF $CRED_FILE
}
rm -f $TF
else
echo "AWSAccessKeyId=${AWS_ACCESS_KEY_ID}" > $CRED_FILE
echo "AWSSecretKey=${AWS_SECRET_ACCESS_KEY}" >> $CRED_FILE
fi
export AWS_CREDENTIAL_FILE=$CRED_FILE
# aws-java-sdk (and ec2-*) use different env names in the default credential provider
# https://github.com/aws/aws-sdk-java/issues/50
export AWS_ACCESS_KEY=${AWS_ACCESS_KEY_ID}
export AWS_SECRET_KEY=${AWS_SECRET_ACCESS_KEY}
# same thing but for the elastic-mapreduce client
if [ -z "$ELASTIC_MAPREDUCE_CREDENTIALS" ]; then
EMR_CRED_FILE=~/.aws_credentials.json
else
EMR_CRED_FILE=$ELASTIC_MAPREDUCE_CREDENTIALS
fi
if [ -f $EMR_CRED_FILE ]; then
# make sure credentials are current
TF=`mktemp -t cred.XXX`
echo "{" > $TF
echo " \"access-id\": \"${AWS_ACCESS_KEY_ID}\"," >> $TF
echo " \"private-key\": \"${AWS_SECRET_ACCESS_KEY}\"" >> $TF
echo "}" >> $TF
# overwrite if different and warn
cmp --quiet $EMR_CRED_FILE $TF || {
echo "WARNING: ELASTIC_MAPREDUCE_CREDENTIALS did not contain the currently set AWS_ACCESS_KEY_ID and/or AWS_SECRET_ACCESS_KEY. Updating $EMR_CRED_FILE with currently set keys." >&2
cp $TF $EMR_CRED_FILE
}
rm -f $TF
else
echo "{" > $EMR_CRED_FILE
echo " \"access-id\": \"${AWS_ACCESS_KEY_ID}\"," >> $EMR_CRED_FILE
echo " \"private-key\": \"${AWS_SECRET_ACCESS_KEY}\"" >> $EMR_CRED_FILE
echo "}" >> $EMR_CRED_FILE
fi
export ELASTIC_MAPREDUCE_CREDENTIALS=$EMR_CRED_FILE