AWS Notes: Difference between revisions
From Federal Burro of Information
Jump to navigationJump to search
Line 150: | Line 150: | ||
* [[/EBS Volume snapshot metrics]] | * [[/EBS Volume snapshot metrics]] | ||
* https://www.youtube.com/watch?v=tzJmE_Jlas0 AWS FSB 301 Security Anti Patterns |
Revision as of 01:47, 22 December 2017
Centos 7 products:
accept lic nad choose a region -> ami id on this page.
List availabe images
Ubuntu:
aws ec2 describe-images \ --filter "Name=state,Values=available" \ "Name=owner-id,Values=099720109477" \ "Name=virtualization-type,Values=paravirtual" \ "Name=root-device-type,Values=instance-store,ebs,ebs-ssd"\ "Name=architecture,Values=x86_64" \ "Name=image-type,Values=machine" \ --output text
Blat Keys
reference: https://alestic.com/2010/10/ec2-ssh-keys/
#!/bin/sh keypair=keyname # or some name that is meaningful to you publickeyfile=/the/file/me.pub regions=$(aws ec2 describe-regions \ --output text \ --query 'Regions[*].RegionName') for region in $regions; do echo $region aws ec2 import-key-pair \ --region "$region" \ --key-name "$keypair" \ --public-key-material "file://$publickeyfile" done
text report
be aware of your "region" set it in command line with --region
list subnets
aws ec2 --query 'Subnets[*].[SubnetId, AvailabilityZone, CidrBlock, AvailableIpAddressCount]' describe-subnets --output text
instances by subnet
aws ec2 --query 'Subnets[*].[SubnetId, CidrBlock]' describe-subnets --output text | while read subnet cidr do echo Subnet ${subnet} ${cidr} for i in `aws ec2 --query 'Reservations[*].Instances[*].[InstanceId]' describe-instances --output text --filter "Name=subnet-id,Values=${subnet}"` do name=`aws ec2 --query 'Tags[*].[Value]' describe-tags --filter "Name=resource-id,Values=${i}" "Name=key,Values=Name" --out text` echo -n ${name} " " aws ec2 --query 'Reservations[*].Instances[*].[State.Name, InstanceId, ImageId, PrivateIpAddress, PublicIpAddress, InstanceType]' describe-instances --output text --filter "Name=subnet-id,Values=${subnet}" "Name=instance-id,Values=${i}" done done
Instances
for i in `aws ec2 --query 'Reservations[*].Instances[*].[InstanceId]' describe-instances --output text` do name=`aws ec2 --query 'Tags[*].[Value]' describe-tags --filter "Name=resource-id,Values=${i}" "Name=key,Values=Name" --out text` echo -n ${name} " " aws ec2 --query 'Reservations[*].Instances[*].[State.Name, InstanceId, ImageId, PrivateIpAddress, PublicIpAddress, InstanceType]' describe-instances --output text --filter "Name=instance-id,Values=${i}" done
Good ref for getting tags : http://docs.aws.amazon.com/cli/latest/reference/ec2/describe-tags.html
getting tags example:
aws ec2 --query 'Tags[*].[Value]' describe-tags --filter "Name=resource-id,Values=<id>"
just an instance's name:
aws ec2 --query 'Tags[*].[Value]' describe-tags --filter "Name=resource-id,Values=<id>" "Name=Key,Value=Name" --out text
list all instance across all regions:
for region in `aws ec2 describe-regions --output text | cut -f3`; do echo -e "\nListing Instances in region:'$region'..."; aws ec2 describe-instances \ --query 'Reservations[*].Instances[*].[PrivateIpAddress, InstanceId, ImageId, PublicIpAddress, State.Name, InstanceType]' \ --output text \ --region $region done
dump all zones
for i in `aws route53 list-hosted-zones --query 'HostedZones[*].[Id]' --output text | cut -f3 -d/` do echo -n "DOMAIN: " aws route53 get-hosted-zone --id $i --query 'HostedZone.[Name]' --output text echo -n "ZONEID: " echo $i; route53 get $i; done > zonereport.txt
Getting the name tag out
how do you extract the "Name" tag in your query?
Tags[?Key==`Name`].Value | [0]
for example:
aws ec2 describe-instances --query 'Reservations[].Instances[].[InstanceId, Tags[?Key==`Name`].Value | [0], State.Name]' --output text
Alerting on activity
http://docs.aws.amazon.com/awscloudtrail/latest/userguide/cloudwatch-alarms-for-cloudtrail.html
- cloudwatch-alarms-for-cloudtrail-signin
- cloudwatch-alarms-for-cloudtrail-authorization-failures
Cloudwatch log filters
http://docs.aws.amazon.com/AmazonCloudWatch/latest/logs/FilterAndPatternSyntax.html
{ ( $.userIdentity.arn = "arn:aws:iam::XXX:user/david.thornton@scalar.ca" ) && ( $.errorCode = "AccessDenied" ) && ( $.userAgent != "[aws-sdk-go/1.12.8 (go1.9; linux; amd64) APN/1.0 HashiCorp/1.0 Terraform/0.10.0-dev]" )}
Also see
- instance costing tool: http://www.ec2instances.info/
- https://www.youtube.com/watch?v=tzJmE_Jlas0 AWS FSB 301 Security Anti Patterns