refactor(snippets/aws): split out command collections

This commit is contained in:
Michele Cereda
2024-11-01 20:57:53 +01:00
parent 7922dc0478
commit f762d8c49c
6 changed files with 44 additions and 45 deletions

View File

@@ -1,2 +1,3 @@
https://azure.microsoft.com/en-us/resources/cloud-computing-dictionary/what-is-cloud-computing
https://cnoe.io/
https://www.youtube.com/watch?v=xfkqNLzQCX8

View File

@@ -0,0 +1,4 @@
#!/usr/bin/env fish
# Get certificates
aws acm get-certificate --certificate-arn 'arn:aws:acm:eu-west-1:012345678901:certificate/abcdef01-2345-6789-abcd-ef0123456789'

21
snippets/aws/cli.fish Normal file
View File

@@ -0,0 +1,21 @@
#!/usr/bin/env fish
# List configured profiles
aws configure list-profiles
# Configure new profiles
aws configure --profile 'engineer'
# Assume roles
aws sts assume-role --role-arn 'arn:aws:iam::012345678901:role/ServiceRole' --role-session-name 'me-as-serviceRole'
aws --profile 'eng' sts assume-role --role-arn 'arn:aws:iam::012345678901:role/ServiceRole' --role-session-name 'eng-as-serviceRole'
# Check the credentials are fine
aws sts get-caller-identity
AWS_PROFILE='engineer' aws sts get-caller-identity
# Run as Docker container
docker run --rm -ti -v "$HOME/.aws:/root/.aws:ro" 'amazon/aws-cli:2.17.16' autoscaling describe-auto-scaling-groups

View File

@@ -0,0 +1,13 @@
#!/usr/bin/env fish
aws deploy list-applications
aws deploy list-deployment-groups --application-name 'Evidently'
aws deploy get-deployment-group --application-name 'Evidently' --deployment-group-name 'production' --output 'json' | pbcopy
diff -y -W 200 \
(aws deploy get-deployment-group --application-name 'Evidently' --deployment-group-name 'staging' --output json | psub) \
(aws deploy get-deployment-group --application-name 'Evidently' --deployment-group-name 'production' --output 'json' | psub)
aws deploy create-deployment --application-name 'Evidently' --deployment-group-name 'staging' \
--description 'This is Evidently a deployment (☞゚∀゚)☞' \
--s3-location 'bundleType=zip,bucket=deployments-bucket,key=evidently-master-staging.zip'

View File

@@ -2,6 +2,7 @@
alias aws-caller-info 'aws sts get-caller-identity'
alias aws-ssm 'aws ssm start-session --target'
alias aws-whoami 'aws-caller-info'
function aws-assume-role-by-name
set current_caller (aws-caller-info --output json | jq -r '.UserId' -)

View File

@@ -1,31 +1,5 @@
#!/usr/bin/env fish
###
# CLI config
# ------------------
###
aws configure list-profiles
aws configure --profile 'engineer'
# Assume roles
aws sts assume-role --role-arn 'arn:aws:iam::012345678901:role/ServiceRole' --role-session-name 'me-as-serviceRole'
aws --profile 'eng' sts assume-role --role-arn 'arn:aws:iam::012345678901:role/ServiceRole' --role-session-name 'eng-as-serviceRole'
# Check the credentials are fine
aws sts get-caller-identity
AWS_PROFILE='engineer' aws sts get-caller-identity
docker run --rm -ti -v "$HOME/.aws:/root/.aws:ro" 'amazon/aws-cli:2.17.16' autoscaling describe-auto-scaling-groups
###
# ACM
# ------------------
###
aws acm get-certificate --certificate-arn 'arn:aws:acm:eu-west-1:012345678901:certificate/abcdef01-2345-6789-abcd-ef0123456789'
###
# Autoscaling Groups
@@ -41,24 +15,6 @@ aws autoscaling cancel-instance-refresh --auto-scaling-group-name 'ProductionSer
aws autoscaling rollback-instance-refresh --auto-scaling-group-name 'ProductionServers'
###
# CodeDeploy
# ------------------
###
aws deploy list-applications
aws deploy list-deployment-groups --application-name 'Evidently'
aws deploy get-deployment-group --application-name 'Evidently' --deployment-group-name 'production' --output 'json' | pbcopy
diff -y -W 200 \
(aws deploy get-deployment-group --application-name 'Evidently' --deployment-group-name 'staging' --output json | psub) \
(aws deploy get-deployment-group --application-name 'Evidently' --deployment-group-name 'production' --output 'json' | psub)
aws deploy create-deployment --application-name 'Evidently' --deployment-group-name 'staging' \
--description 'This is Evidently a deployment (☞゚∀゚)☞' \
--s3-location 'bundleType=zip,bucket=deployments-bucket,key=evidently-master-staging.zip'
###
# EC2
# ------------------
@@ -80,7 +36,8 @@ aws ec2 describe-images --output 'yaml' \
aws iam list-instance-profiles | grep -i 'ssm'
# Check instances are available for use with SSM
aws ssm get-connection-status --query "Status=='connected'" --output 'text' --target "i-0915612ff82914822"
aws ssm get-connection-status --query "Status=='connected'" --output 'text' --target 'i-0915612ff82914822'
aws ssm describe-instance-associations-status --instance-id 'i-0f8b61c78622caed2'
# From the instance
sudo ssm-cli get-diagnostics --output 'table'
@@ -90,6 +47,8 @@ instance_id='i-08fc83ad07487d72f' \
&& aws ssm start-session --target "$instance_id" \
|| (echo "instance ${instance_id} not available" >&2 && false)
aws ssm describe-instance-associations-status --instance-id 'i-08fc83ad07487d72f'
# Send commands
aws ssm send-command --instance-ids 'i-08fc83ad07487d72f' --document-name 'AWS-RunShellScript' --parameters "commands='echo hallo'"
aws ssm wait command-executed --command-id 'e5f7ca0e-4d74-4316-84be-9ccaf3ae1f70' --instance-id 'i-08fc83ad07487d72f'