Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

✨Autoscaling/Clusters-keeper tags also volume and network-interface #5405

Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
41 changes: 24 additions & 17 deletions packages/aws-library/src/aws_library/ec2/client.py
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@
from settings_library.ec2 import EC2Settings
from types_aiobotocore_ec2 import EC2Client
from types_aiobotocore_ec2.literals import InstanceStateNameType, InstanceTypeType
from types_aiobotocore_ec2.type_defs import FilterTypeDef
from types_aiobotocore_ec2.type_defs import FilterTypeDef, TagTypeDef

from .errors import (
EC2InstanceNotFoundError,
Expand Down Expand Up @@ -124,24 +124,27 @@ async def start_aws_instance(
if len(current_instances) + number_of_instances > max_number_of_instances:
raise EC2TooManyInstancesError(num_instances=max_number_of_instances)

resource_tags: list[TagTypeDef] = [
{"Key": tag_key, "Value": tag_value}
for tag_key, tag_value in instance_config.tags.items()
]

instances = await self.client.run_instances(
ImageId=instance_config.ami_id,
MinCount=number_of_instances,
MaxCount=number_of_instances,
IamInstanceProfile={"Arn": instance_config.iam_instance_profile}
if instance_config.iam_instance_profile
else {},
IamInstanceProfile=(
{"Arn": instance_config.iam_instance_profile}
if instance_config.iam_instance_profile
else {}
),
InstanceType=instance_config.type.name,
InstanceInitiatedShutdownBehavior="terminate",
KeyName=instance_config.key_name,
TagSpecifications=[
{
"ResourceType": "instance",
"Tags": [
{"Key": tag_key, "Value": tag_value}
for tag_key, tag_value in instance_config.tags.items()
],
}
{"ResourceType": "instance", "Tags": resource_tags},
{"ResourceType": "volume", "Tags": resource_tags},
{"ResourceType": "network-interface", "Tags": resource_tags},
],
UserData=compose_user_data(instance_config.startup_script),
NetworkInterfaces=[
Expand Down Expand Up @@ -172,9 +175,11 @@ async def start_aws_instance(
launch_time=instance["LaunchTime"],
id=instance["InstanceId"],
aws_private_dns=instance["PrivateDnsName"],
aws_public_ip=instance["PublicIpAddress"]
if "PublicIpAddress" in instance
else None,
aws_public_ip=(
instance["PublicIpAddress"]
if "PublicIpAddress" in instance
else None
),
type=instance["InstanceType"],
state=instance["State"]["Name"],
tags=parse_obj_as(
Expand Down Expand Up @@ -234,9 +239,11 @@ async def get_instances(
launch_time=instance["LaunchTime"],
id=instance["InstanceId"],
aws_private_dns=instance["PrivateDnsName"],
aws_public_ip=instance["PublicIpAddress"]
if "PublicIpAddress" in instance
else None,
aws_public_ip=(
instance["PublicIpAddress"]
if "PublicIpAddress" in instance
else None
),
type=instance["InstanceType"],
state=instance["State"]["Name"],
resources=ec2_instance_types[0].resources,
Expand Down
Loading