-
Notifications
You must be signed in to change notification settings - Fork 2
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
158dfca
commit b31066c
Showing
58 changed files
with
1,579 additions
and
9 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,12 @@ | ||
*.sh | ||
.env | ||
.fun | ||
build.sh | ||
exec.sh | ||
logs.sh | ||
pull.sh | ||
push.sh | ||
run.sh | ||
status.sh | ||
stop.sh | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,45 @@ | ||
#!/bin/bash | ||
|
||
###################################################################### | ||
# Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved. # | ||
# SPDX-License-Identifier: Apache-2.0 # | ||
###################################################################### | ||
|
||
# Source helper functions | ||
source .fun | ||
|
||
# Proxy settings [optional] - set if your network requires a proxy to connect to the Internet | ||
export http_proxy= | ||
export https_proxy= | ||
export no_proxy=localhost | ||
|
||
# Docker image settings | ||
## REGISTRY: [optional] - Docker registry path including trailing "/". Example: registry.company.com/demo/ | ||
export REGISTRY=594704452476.dkr.ecr.us-west-2.amazonaws.com/ | ||
if [ -n "${REGISTRY}" ]; then | ||
if [ "${REGISTRY: -1}" != "/" ]; then | ||
export REGISTRY="${REGISTRY}/" | ||
fi | ||
fi | ||
## IMAGE: <required> - Docker image name for this project. Example: myapp | ||
export IMAGE=aws-do-cli | ||
## VERSION: [optional] - Version tag for this Docker image. Example: v20180302 | ||
#export VERSION=v$(date +%Y%m%d) | ||
export VERSION=latest | ||
export TAG=$(if [ -z "${VERSION}" ]; then echo ""; else echo ":${VERSION}"; fi) | ||
## BUILD_OPTS: [optional] - arguments for the docker image build command | ||
export BUILD_OPTS="--progress=plain --build-arg http_proxy=${http_proxy} --build-arg https_proxy=${https_proxy} --build-arg no_proxy=${no_proxy}" | ||
|
||
# Docker container runtime settings | ||
## CONTAINER_NAME: [optional] - Name of the Docker container including the --name switch. Example --name myapp | ||
export CONTAINER=${IMAGE} | ||
export CONTAINER_NAME="--name ${CONTAINER}" | ||
## Port map [optional] - Mapping of external to internal ports including the -p switch. Example -p 80:8080 | ||
#export PORT_MAP="-p 80:8080" | ||
## Volume map [optional] - Mapping of external to internal paths including the -v switch. Example $(pwd):/wd | ||
export VOL_MAP="-v ${HOME}/.aws:/root/.aws -v $(pwd):/wd" | ||
## Network [optional] - Network name including the --net switch. Example --net mynet | ||
export NETWORK= | ||
## RUN_OPTS [optional] - additional options to specify with the run comman. Example -e POSTGRES_DB=dbname | ||
export RUN_OPTS="-e http_proxy=$http_proxy -e https_proxy=$https_proxy -e no_proxy=$no_proxy" | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,47 @@ | ||
#!/bin/bash | ||
|
||
###################################################################### | ||
# Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved. # | ||
# SPDX-License-Identifier: Apache-2.0 # | ||
###################################################################### | ||
|
||
# Helper functions | ||
## Detect current operating system | ||
function os | ||
{ | ||
UNAME=$(uname -a) | ||
if [ $(echo $UNAME | awk '{print $1}') == "Darwin" ]; then | ||
export OPERATING_SYSTEM="MacOS" | ||
elif [ $(echo $UNAME | awk '{print $1}') == "Linux" ]; then | ||
export OPERATING_SYSTEM="Linux" | ||
elif [ ${UNAME:0:5} == "MINGW" ]; then | ||
export OPERATING_SYSTEM="Windows" | ||
export MSYS_NO_PATHCONV=1 # turn off path conversion | ||
else | ||
export OPERATING_SYSTEM="Other" | ||
fi | ||
} | ||
## End os function | ||
os | ||
|
||
## Determine current host IP address | ||
function hostip | ||
{ | ||
case "${OPERATING_SYSTEM}" in | ||
"Linux") | ||
export HOST_IP=$(hostname -I | tr " " "\n" | head -1) # Linux | ||
;; | ||
"MacOS") | ||
export HOST_IP=$(ifconfig | grep -v 127.0.0.1 | grep -v inet6 | grep inet | head -n 1 | awk '{print $2}') # Mac OS | ||
;; | ||
"Windows") | ||
export HOST_IP=$( ((ipconfig | grep IPv4 | grep 10.187 | tail -1) && (ipconfig | grep IPv4 | grep 3. | head -1)) | tail -1 | awk '{print $14}' ) # Git bash | ||
;; | ||
*) | ||
export HOST_IP=$(hostname) | ||
;; | ||
esac | ||
} | ||
## End hostip function | ||
hostip | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,2 @@ | ||
wd | ||
Container-Root/aws-do-cli/ec2/ec2-template/launch-template-*.json |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,36 @@ | ||
#!/bin/bash | ||
|
||
###################################################################### | ||
# Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved. # | ||
# SPDX-License-Identifier: Apache-2.0 # | ||
###################################################################### | ||
|
||
source ./ec2.conf | ||
|
||
function usage(){ | ||
echo "" | ||
echo "Usage: $0 <auto_scaling_group_name> <template_id> <min_size> <max_size> <desired_size>" | ||
echo "" | ||
} | ||
|
||
if [ "$5" == "" ]; then | ||
usage | ||
else | ||
echo "" | ||
echo "Creating Auto Scaling Group $1 from Launch Template $2 ..." | ||
# Check if launch template exists | ||
CMD="aws ec2 describe-launch-templates --launch-template-ids $2 > /dev/null" | ||
eval "$CMD" | ||
if [ "$?" == "0" ]; then | ||
CMD="aws autoscaling create-auto-scaling-group --auto-scaling-group-name $1 --launch-template LaunchTemplateId=$2 --min-size $3 --max-size $4 --desired-capacity $5" | ||
echo "" | ||
eval "$CMD" | ||
if [ "$?" == "0" ]; then | ||
echo "Auto Scaling Group $1 created." | ||
else | ||
echo "Failed to create Auto Scaling Group $1" | ||
fi | ||
fi | ||
echo "" | ||
fi | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,36 @@ | ||
#!/bin/bash | ||
|
||
###################################################################### | ||
# Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved. # | ||
# SPDX-License-Identifier: Apache-2.0 # | ||
###################################################################### | ||
|
||
source ./ec2.conf | ||
|
||
function usage(){ | ||
echo "" | ||
echo "Usage: $0 <auto_scaling_group_name>" | ||
echo "" | ||
} | ||
|
||
if [ "$1" == "" ]; then | ||
usage | ||
else | ||
echo "" | ||
echo "Deleting Auto Scaling Group $1 ..." | ||
# Check if auto scaling group exists | ||
CMD="aws ec2 describe-auto-scaling-groups --auto-scaling-group-names $1 > /dev/null" | ||
eval "$CMD" | ||
if [ "$?" == "0" ]; then | ||
CMD="aws autoscaling delete-auto-scaling-group --auto-scaling-group-name $1" | ||
echo "" | ||
eval "$CMD" | ||
if [ "$?" == "0" ]; then | ||
echo "Auto Scaling Group $1 deleted." | ||
else | ||
echo "Failed to delete Auto Scaling Group $1" | ||
fi | ||
fi | ||
echo "" | ||
fi | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,15 @@ | ||
#!/bin/bash | ||
|
||
###################################################################### | ||
# Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved. # | ||
# SPDX-License-Identifier: Apache-2.0 # | ||
###################################################################### | ||
|
||
source ./ec2.conf | ||
|
||
echo "" | ||
echo "Listing auto scaling groups ..." | ||
echo "" | ||
CMD="aws autoscaling describe-auto-scaling-groups --query 'AutoScalingGroups[*].{Name: AutoScalingGroupName,LaunchTemplate: MixedInstancesPolicy.LaunchTemplate.LaunchTemplateSpecification.LaunchTemplateId, MinSize: MinSize, MaxSize: MaxSize, TargetSize: DesiredCapacity, CurrentSize: length(Instances), Subnet: VPCZoneIdentifier}' --output ${output_format}" | ||
echo "$CMD" | ||
eval "$CMD" |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,36 @@ | ||
#!/bin/bash | ||
|
||
###################################################################### | ||
# Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved. # | ||
# SPDX-License-Identifier: Apache-2.0 # | ||
###################################################################### | ||
|
||
source ./ec2.conf | ||
|
||
function usage(){ | ||
echo "" | ||
echo "Usage: $0 <auto_scaling_group_name> <min_size> <max_size> <desired_size>" | ||
echo "" | ||
} | ||
|
||
if [ "$4" == "" ]; then | ||
usage | ||
else | ||
echo "" | ||
echo "Updating Auto Scaling Group $1 ..." | ||
# Check if auto scaling group exists | ||
CMD="aws autoscaling describe-auto-scaling-groups --auto-scaling-group-names $1 > /dev/null" | ||
eval "$CMD" | ||
if [ "$?" == "0" ]; then | ||
CMD="aws autoscaling update-auto-scaling-group --auto-scaling-group-name $1 --min-size $2 --max-size $3 --desired-capacity $4" | ||
echo "" | ||
eval "$CMD" | ||
if [ "$?" == "0" ]; then | ||
echo "Auto Scaling Group $1 updated." | ||
else | ||
echo "Failed to update Auto Scaling Group $1" | ||
fi | ||
fi | ||
echo "" | ||
fi | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,9 @@ | ||
#!/bin/bash | ||
|
||
###################################################################### | ||
# Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved. # | ||
# SPDX-License-Identifier: Apache-2.0 # | ||
###################################################################### | ||
|
||
vi ./ec2.conf | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,10 @@ | ||
#!/bin/bash | ||
|
||
###################################################################### | ||
# Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved. # | ||
# SPDX-License-Identifier: Apache-2.0 # | ||
###################################################################### | ||
|
||
source ec2.conf | ||
|
||
sed -i.bak "s/^[#]*\s*current_vpc=.*/current_vpc=$1/" ec2.conf |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,21 @@ | ||
#!/bin/bash | ||
|
||
###################################################################### | ||
# Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved. # | ||
# SPDX-License-Identifier: Apache-2.0 # | ||
###################################################################### | ||
|
||
source ./ec2.conf | ||
|
||
filters="--filters Name=root-device-type,Values=ebs" | ||
if [ "${response_format}" == "short" ]; then | ||
CMD="aws ec2 describe-images --owners self amazon --query \"Images[*].{ImageId:ImageId,ImageName:Name,Platform:PlatformDetails,Owner:ImageOwnerAlias}\" $filters --output ${output_format}" | ||
|
||
else | ||
CMD="aws ec2 describe-images --owners self amazon --query \"Images[*].{ImageId:ImageId,ImageName:Name,Description:Description,Platform:PlatformDetails,Owner:ImageOwnerAlias}\" $filters --output ${output_format}" | ||
|
||
fi | ||
|
||
echo "$CMD" | ||
eval "$CMD" | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,23 @@ | ||
#!/bin/bash | ||
|
||
###################################################################### | ||
# Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved. # | ||
# SPDX-License-Identifier: Apache-2.0 # | ||
###################################################################### | ||
|
||
source ./ec2.conf | ||
|
||
echo "" | ||
|
||
if [ "$EC2_INSTANCE_NAME" == "" ]; then | ||
echo "Please configure all settings in the EC2 Instance Configuration section of ./ec2.conf" | ||
echo "Then run $0 again to launch the instance" | ||
else | ||
echo "Launching instance $EC2_INSTANCE_NAME ..." | ||
CMD="aws ec2 run-instances --image-id $EC2_IMAGE_ID --block-device-mappings \"DeviceName=/dev/sda1,Ebs={DeleteOnTermination=true,VolumeSize=$EC2_VOLUME_SIZE_GB,VolumeType=gp3,Encrypted=true}\" --instance-type $EC2_INSTANCE_TYPE --iam-instance-profile \"Name=$EC2_INSTANCE_PROFILE_NAME\" --network-interfaces \"AssociatePublicIpAddress=$EC2_ASSIGN_PUBLIC_IP,DeviceIndex=0,Groups=$EC2_SG_ID,SubnetId=$EC2_SUBNET_ID\" --tag-specifications \"ResourceType=instance,Tags=[{Key=Name,Value=$EC2_INSTANCE_NAME}]\" --key-name $EC2_KEY_NAME" | ||
echo "$CMD" | ||
eval "$CMD" | ||
fi | ||
|
||
echo "" | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,24 @@ | ||
#!/bin/bash | ||
|
||
###################################################################### | ||
# Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved. # | ||
# SPDX-License-Identifier: Apache-2.0 # | ||
###################################################################### | ||
|
||
source ./ec2.conf | ||
|
||
if [ ! "$current_vpc" == "" ]; then | ||
filters="--filters Name=vpc-id,Values=${current_vpc}" | ||
fi | ||
|
||
if [ "${response_format}" == "long" ]; then | ||
CMD="aws ec2 describe-instances --query \"Reservations[*].Instances[*].{InstanceId:InstanceId,Keypair:KeyName,InstanceType:InstanceType,ImageId:ImageId,PrivateIpAddress:PrivateIpAddress,AvailabilityZone:Placement.AvailabilityZone,SubnetId:SubnetId,VpcId:VpcId,Status:State.Name,PublicDnsName:PublicDnsName,Name:Tags[?Key=='Name']|[0].Value}\" $filters --output ${output_format}" | ||
|
||
else | ||
CMD="aws ec2 describe-instances --query \"Reservations[*].Instances[*].{InstanceId:InstanceId,Keypair:KeyName,InstanceType:InstanceType,PrivateIpAddress:PrivateIpAddress,SubnetId:SubnetId,Status:State.Name,Name:Tags[?Key=='Name']|[0].Value}\" $filters --output ${output_format}" | ||
|
||
fi | ||
|
||
#echo "$CMD" | ||
eval "$CMD" | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,19 @@ | ||
#!/bin/bash | ||
|
||
###################################################################### | ||
# Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved. # | ||
# SPDX-License-Identifier: Apache-2.0 # | ||
###################################################################### | ||
|
||
source ./ec2.conf | ||
|
||
if [ "${response_format}" == "long" -o "$1" == "long" ]; then | ||
CMD="aws iam list-instance-profiles --query \"InstanceProfiles[*].{InstanceProfileId:InstanceProfileId,InstanceProfileName:InstanceProfileName,Arn:Arn,Role0:Roles[0].RoleName,Role1:Roles[1].RoleName}\" --output ${output_format}" | ||
else | ||
CMD="aws iam list-instance-profiles --query \"InstanceProfiles[*].{InstanceProfileId:InstanceProfileId,InstanceProfileName:InstanceProfileName,Role0:Roles[0].RoleName,Role1:Roles[1].RoleName}\" --output ${output_format}" | ||
|
||
fi | ||
|
||
echo "$CMD" | ||
eval "$CMD" | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,36 @@ | ||
#!/bin/bash | ||
|
||
###################################################################### | ||
# Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved. # | ||
# SPDX-License-Identifier: Apache-2.0 # | ||
###################################################################### | ||
|
||
source ./ec2.conf | ||
|
||
function usage(){ | ||
echo "" | ||
echo "Usage: $0 <instnce_id>" | ||
echo "" | ||
} | ||
|
||
if [ "$1" == "" ]; then | ||
usage | ||
else | ||
echo "" | ||
echo "Starting instance $1 ..." | ||
# Check if instance exists | ||
CMD="aws ec2 describe-instances --instance-ids $1 > /dev/null" | ||
eval "$CMD" | ||
if [ "$?" == "0" ]; then | ||
CMD="aws ec2 start-instances --instance-ids $1 > /dev/null" | ||
echo "" | ||
eval "$CMD" | ||
if [ "$?" == "0" ]; then | ||
echo "Instance $1 started." | ||
else | ||
echo "Failed to start instance $1" | ||
fi | ||
fi | ||
echo "" | ||
fi | ||
|
Oops, something went wrong.