I have a yes or no question.
I am trying to find out list of instances from our current AWS infrastructure based on their virtualization type.
ex: query to find list of instances which are pvm.
I tried using the query command and filter command. But no gains yet.
Can we even query to get the virtualization type?
Thanks in advance.
ec2 describe instance list many arguments about the instance, including the virtualisation type
virtualization-type - The virtualization type of the instance (paravirtual | hvm ).
so you can use the following commands
aws ec2 describe-instances \
--query 'Reservations[*].Instances[?VirtualizationType==`hvm`]'
this will return all instances (in the specific region) where virtualisation type is hvm. You can adjust for pvm:
aws ec2 describe-instances \
--query 'Reservations[*].Instances[?VirtualizationType==`paravirtual`]'
Related
I have my AWS account. I have created multiple member users instead of IAM Users.
Memebers usera has created multiple EC2 instances & other resources.
Can we get a list of running instances created by memeber users, through CLI ?
In your comment you asked: "How can we get the list of running instances in AWS through AWS CLI"
This AWS CLI command will list instances filtered by State, returning the Instance ID:
aws ec2 describe-instances --filters Name=instance-state-name,Values=running --query Reservations[].Instances[].InstanceId --output text
This will list all running Amazon EC2 instances in your account for the default region that you have defined in the AWS CLI configuration.
It is not possible to limit the listing to only instances launched by specific people. Once an instance is launched, it belongs to the AWS Account and is not associated with a specific IAM User. If you wish to track usage by specific users, either add a Tag to the resource or use AWS CloudTrail to identify who launched the instance.
Is there a way to view/monitor AWS Sagemaker's usage of EC2 instances?
I am running a Sagemaker endpoint and tried to find its instances (ml.p3.2xlarge in this case) in the EC2 UI, but couldn't find them.
ml EC2 instances do not appear in the EC2 console. You can find their metrics in Cloudwatch though, and create dashboards to monitor what you need:
I'm aware that there are similar question posted here, but none of them address this specific issue.
How to create an ECS cluster via CLI tools, aws-cli and/or ecs-cli, with using your own custom AMI stored in EC2 as an AMI image?
Is this even possible currently or do I need to turn to CloudFormation?
EDIT: I had a major confusion about the service architecture of ECS in terms of distributing containers on container instances (EC2 instances registered to the cluster).
So the container instance runs on an AMI. Which can be a custom built AMI, but such would needed only in some special circumstances. It's recommended to use an ECS-optimized Amazon Linux AMI by as maintained by AWS and is updated about once a month.
Another confusion point was with Docker Compose approach and the ECS CLI tool. Some experts think that while the ECS CLI is released and maintained by AWS, and being already 3 years old at this point in 2019, it is not suitable for production usage. So am using AWS CLI instead, and dealing with clusters, task definitions, and (task scheduling) services directly.
I would rather run the custom stuff within the container defined by dockerfile on ECS optimized AMI
But to run custom AMI
1) Pre-requisite is to have AMI image with ECS Agent installed
2) Then I would try ecs-cli up command with defined --image-id
ecs-cli up
--keypair <my-keypair>
--launch-type EC2
--size 2
--instance-type t2.micro
--instance-role ECSMediumRole
--vpc <my-vpc>
--image-id ami-XXXXXXXX # Custom Image ID with ECS Agent installed
--cluster-config <my-cluster-config>
--ecs-profile <my-ecs-profile>
--security-group <my-security-group-id>
--region us-east-1
--subnets <my-public-vpc-subnet>
I have a requirement to launch multiple EC2 instances in the Tokyo region, based on the number of AMIs owned by our account in that same region. The AMIs are backed-up daily from another region.
What this CloudFormation needs to achieve is:
Retrieve a list of AMIs created today
Attempt to launch each of them in the same region
For example, if today there are 10 different AMIs created in the Tokyo region, then CloudFormation will then create 10 EC2 instances based on these 10 AMIs.
I have looked at some examples at Walkthrough: Looking Up Amazon Machine Image IDs - AWS CloudFormation but found the code does not suit the requirement.
I already have the Lambda function retrieve-today-ami.py, the challenge is to include them in the CF template found in Walkthrough: Looking Up Amazon Machine Image IDs - AWS CloudFormation
Normally, CloudFormation is used to launch pre-defined infrastructure. Your requirement to launch a variable number of instances with information that changes for each instance every day, does not match the model for using CloudFormation.
Based on your use-case, I would recommend writing a script to perform the operation you want.
For example, a Python scripts that lists the AMIs, identifies the ones you want to use, then launches EC2 instances using those AMIs.
You might be able to achieve this by using a Lambda-backed custom resource to fetch the names of the AMIs. Then, the outputs of your custom resource could be used in the EC2 stanzas in the template. You could have the one template defining the Lambda export the values and import them on your EC2 templates.
I just have created Amazon EC2 image and I'm new to this environment.
I'm interested in "auto scale" part of Amazon EC2.
But I could not find clear guide to find whether I'm using "auto scale" or not and how to auto scale my instance.
How can I setup "auto scale" properly and easily?
Here are some links that might help you setup auto-scaling:
http://kkpradeeban.blogspot.com/2011/01/auto-scaling-with-amazon-ec2.html
http://www.codebelay.com/blog/2009/08/02/how-to-load-balance-and-auto-scale-with-amazons-ec2/
You will need to download, unzip and setup the Auto Scaling Command Line Tool
You will need an AMI e.g. ami-xxxxxx
and a security group e.g. my-securitygroup-sg
and a key e.g. myKey
Now create a Launch Configuration, in this case called: my-launch-config-1
as-create-launch-config my-launch-config-1 --image-id ami-xxxxxx --region eu-west-1 --instance-type m1.small --group my-securitygroup-sg --key myKey
Then you can create the Auto Scaling Group
as-create-auto-scaling-group my-auto-scaling-group --region eu-west-1 --launch-configuration my-launch-config-1 --availability-zones eu-west-1a eu-west-1b eu-west-1c --min-size 3 --max-size 3 --desired-capacity 3 --default-cooldown 5 --grace-period 5 --tag "k=Name, v=my-servers, p=true" --tag "k=enabled, v=true, p=true"
This will create 3 instances base on the AMI, one in each zone
You can check on the progress of the creation of the Auto Scaling group using this command
as-describe-scaling-activities --auto-scaling-group my-auto-scaling-group --region eu-west-1
You can find more useful commands for things like deleting or updating Auto Scaling Group in my blog post:
How to use Amazon’s Auto Scaling Groups
Or there is the Amazon Web Services getting started documentation
You also have a look into this blog,
http://geekospace.com/installing-aws-command-line-tools-from-amazon-downloads/
Auto Scaling is a tool that uses the results from Amazon CloudWatch to define the scaling policies on various instances.
Auto Scaling gives you power to decide the scaling, Schedule it and also define the resource to be scaled. These configurations are stored under an Auto Scaling Group and can be used to track applications working over various instances.