Skip to content

Instantly share code, notes, and snippets.

@Calrion
Last active December 17, 2015 16:39
Show Gist options
  • Save Calrion/5640713 to your computer and use it in GitHub Desktop.
Save Calrion/5640713 to your computer and use it in GitHub Desktop.
Shell script to obtain AWS access and secret key credentials. This script isn't designed to be used on its own (though it's a great self-contained tester for checking your setup) but rather incorporated into a larger script, which then makes use of the credentials to access AWS resources.
#!/bin/sh
# Shell script to obtain AWS access and secret key credentials.
# Written by Greg Waterhouse, 2013-05-23.
# Copyright 2013 Greg Waterhouse
#
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
# You may obtain a copy of the License at
#
# http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.
if [ -f "${AWS_CONFIG_FILE}" ]; then
AWS_KEY=`grep aws_access_key_id "$AWS_CONFIG_FILE" | awk '{split($0,a,"="); print a[2]}'`
AWS_SECRET=`grep aws_secret_access_key "$AWS_CONFIG_FILE" | awk '{split($0,a,"="); print a[2]}'`
else
AWS_KEY=${AWS_ACCESS_KEY_ID="UNSET"}
AWS_SECRET=${AWS_SECRET_KEY="UNSET"}
fi
if [ ${AWS_KEY} = "UNSET" ]; then
echo "${0##*/}: error: Amazon AWS access key not found."; exit 1
fi
if [ ${AWS_SECRET} = "UNSET" ]; then
echo "${0##*/}: error: Amazon AWS secret key not found."; exit 1
fi
echo "${0##*/}: \c"
echo "Using AWS access key \"${AWS_KEY}\" and secret key \"${AWS_SECRET}\".\n"
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment