Compute¶
Regions¶
The “EC2ComputeManager” class requires a list of regions to be provided in the constructor. The regions are used to find the best region to launch the EC2 instance. The regions are ordered by preference, so the first region in the list will be used if it is available. If the first region is not available, the next region in the list will be used, and so on.
Placement priority is determined based on region and instance types. The “EC2ComputeManager” will try to launch the instance in the first region in the list that has the instance type available. If the instance type is not available in the first region, the next instance type in the list will be tried before moving onto the next region.
You can instantiate a region as:
from moveai_mocap.compute.models.region import Region
ireland_region = Region(
ec2_boto3_client=boto3.client("ec2", region_name="eu-west-1"),
subnet_ids=["subnet-1", "subnet-2"],
security_group_ids=["sg-1", "sg-2"],
ami_id="ami-12345678",
)
Instance Types¶
By default the “EC2ComputeManager” will try to allocate an ec2 instance with a type set in the InstanceTypes Enum. Please follow the table below to set the instance type according to the number of cameras and the duration of the capture:
Num. of Cameras |
Duration |
Min. Instance Type |
|---|---|---|
6 or less |
|
|
between 6 & 11 |
— |
g6.2xlarge |
12 or more |
— |
g6.4xlarge |
You can define your custom InstanceTypes Enum class, and set the instance_types parameter in the EC2ComputeManager constructor accordingly:
# define the instance types enum:
from moveai_mocap.compute.ec2 import InstanceTypes
from enum import Enum
class LargeVolumeInstanceTypes(Enum):.
"""The AWS EC2 instance types to use - in order."""
g6_2xlarge = "g6.2xlarge"
g6_4xlarge = "g6.4xlarge"
g6_8xlarge = "g6.8xlarge"
ireland_region = Region(
ec2_boto3_client=boto3.client(
"ec2",
region_name="eu-west-1",
aws_access_key_id="your-access-key",
aws_secret_access_key="*************",
),
subnet_ids=["subnet-1", "subnet-2"],
security_group_ids=["sg-1", "sg-2"],
ami_id="ami-12345678",
)
n_virginia_region = Region(
ec2_boto3_client=boto3.client(
"ec2",
region_name="us-east-1",
aws_access_key_id="your-access-key",
aws_secret_access_key="*************",
),
subnet_ids=["subnet-1", "subnet-2"],
security_group_ids=["sg-1", "sg-2"],
ami_id="ami-12345678",
)
# create the EC2ComputeManager with the instance type parameter
compute = EC2ComputeManager(
# configure these settings according to your AWS account
iam_instance_profile_name="instance-profile-name",
regions=[ireland_region, n_virginia_region],
notifier=sns_notifier,
instance_types=LargeVolumeInstanceTypes
)
Instance Permissions¶
- The EC2 instance needs to have the following permissions to run the MoveAI Mocap software:
S3 read/write permissions
SNS publish permissions
Here is an example of an IAM policy that grants the required permissions:
{
"Version": "2012-10-17",
"Statement": [
{
"Action": [
"s3:PutObject",
"s3:GetObjectAcl",
"s3:GetObject",
"s3:PutObjectTagging",
"s3:DeleteObjectVersionTagging"
],
"Resource": [
"arn:aws:s3:::MY_S3_BUCKET/*",
"arn:aws:s3:::MY_S3_BUCKET"
],
"Effect": "Allow"
},
{
"Action": [
"sns:Publish"
],
"Resource": "MY_SNS_TOPIC_ARN",
"Effect": "Allow"
}
]
}
Replace “MY_S3_BUCKET” with the name of the S3 bucket you want to use, and “MY_SNS_TOPIC_ARN” with the ARN of the SNS topic you want to use.
Trust policy to EC2 service:
{
"Version": "2012-10-17",
"Statement": [
{
"Effect": "Allow",
"Principal": {
"Service": "ec2.amazonaws.com"
},
"Action": "sts:AssumeRole"
}
]
}