Trying to create snapshot of ebs volume. I have the below command in aws cli windows
aws --profile ade --region us-east-1 ec2 create-snapshot --volume-id vol-
012709ebb854c5fdd --description 'c-drive of i-00ca23fae0887e018' --tags-
specifications 'ResourceType=snapshot,Tags=[{Key=Product,Value=csf},
{Key=Service,Value=datamigration},{Key=Name,Value=cdrive-dms},
{Key=Team,Value=DMS},{Key=Owner,Value=alexwolff}]'
I get response:
Uknown options: --tag-specifications, ResourceType=snapshot,Tags[{Key=Product,Value=csf},{Key=Service,Value=datamigration},{Key=Name,Value=cdrive-dms},{Key=Team,Value=DMS},{Key=Owner,Value=alexwolff}]
It's got to be a simple syntax mistake...can anybody spot it? I've tried switching single quotes to double quotes and vice-versa.
Thank you.
The syntax that ended up working for me was:
aws --profile ade --region us-east-1 ec2 create-snapshot --volume-id vol-
012709ebb854c5fdd --description "c-drive of i-00ca23fae0887e018" --tag-specification
'ResourceType=snapshot,Tags=[{Key=Product,Value=csf},{Key=Service,Value=datamigration},
{Key=Name,Value=cdrive-dms},{Key=Team,Value=DMS},{Key=Owner,Value=alexwolff}]'
tag-specification
Related
In AWS Backup, I have created a resource assignment to a backup-plan, which targets all EC2 instances.
The ARN prefix looks like this:
arn:aws:ec2:*:*:instance/*
How can I list all instances that match an ARN prefix? Either in AWS Cloudshell or with the aws cli?
I think you can try using ec2's describe-instances cli command and run it over all AWS regions :
for region in `aws ec2 describe-regions --output text | cut -f3`
do
echo -e "\nListing Instances in region:'$region'..."
aws ec2 describe-instances --region $region
done
I am executing the command below in AWS CLI to find volumes that have size>=200GIB but the command returns nothing. But from the AWS console I can see that few volumes have a size >=200GiB
aws ec2 describe-volumes --filter "Name=size,Values= >=200GiB"
You can use the following:
aws ec2 describe-volumes --query 'Volumes[?Size > `250`].[VolumeId,Size]' --output text
I think correct format is
aws ec2 describe-volumes --query "Volumes[?Size > 100].{tag:Tags,ID:VolumeId,size:Size,type:VolumeType}"
Above command is working at my end
i am trying to fetch VPC details for all region.i tried to run my script without default profile which results in error "You must specify a region. You can also configure your region by running "aws configure" ,evnthough i have my own profile configured with all required details for it.
same script works fine after configuring default profile.
Question is does AWS CLI requires default profile as mandatory ?
My script
for region in `aws ec2 describe-regions --output text| cut -f4`
do
aws ec2 --profile sam --region $region --output text --query 'Vpcs[*].{VpcId:VpcId,CidrBlock:CidrBlock}'
describe-vpcs
done
cat .aws/config
[profile sam]
output = json
region = us-east-1
If you don’t have a default profile configured, you can define the target profile with the --profile option.
aws ec2 describe-regions --profile profile-name
Another way is to set the AWS_PROFILE environment variable. This way you don’t have to explicitly add the option for every AWS CLI command.
export AWS_PROFILE=profile-name
Seems a bug in your script. I tried the below and it worked for me.
for region in `aws ec2 describe-regions --output text| cut -f4`
do
aws ec2 describe-vpcs --profile <myProfile> --region $region --output text --query 'Vpcs[*].{VpcId:VpcId,CidrBlock:CidrBlock}'
done
found the issue , need to add --profile in my first line of code as well.It works fine now.
for region in `aws ec2 describe-regions --profile sam --output text| cut -f4
I am following the documentation to use the --query option in aws cli. However it doesn't work for me at all. I have defined profiles because I have several accounts to pull the data. If I omit the --query, it returns the data successfully. Any insight into this please?
Thank you
> aws --version
aws-cli/1.14.8 Python/3.6.3 Windows/10 botocore/1.8.12
> aws ec2 describe-volumes --profile TEST1 --region us-east-1 --query 'Volumes[0]'
"Volumes[0]"
> aws ec2 describe-volumes --profile TEST1 --region us-east-1
{
"Volumes": [
{
"Attachments": [ ....
Change from single quotes to double quotes:
aws ec2 describe-volumes --profile TEST1 --region us-east-1 --query "Volumes[0]"
As soon as i switched to powershell, it works successfully. Although I am not sure why it requires using powershell.
Could not connect to the endpoint URL: "https://ec2.ec2-east.amazonaws.com/" is throwing
You do not use a valid region (ec2-east)
For ec2 regions, please refer to http://docs.aws.amazon.com/general/latest/gr/rande.html#ec2_region
Your command should be aws ec2 describe-instances --region xxx where xxx is in the list from http://docs.aws.amazon.com/general/latest/gr/rande.html#ec2_region like aws ec2 describe-instances --region us-east-1