Skip to content
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
19 changes: 17 additions & 2 deletions tests/system/providers/amazon/aws/example_ec2.py
Original file line number Diff line number Diff line change
Expand Up @@ -50,11 +50,20 @@ def get_latest_ami_id():
# on how they name the new images. This page should have AL2022 info when
# it comes available: https://aws.amazon.com/linux/amazon-linux-2022/faqs/
image_prefix = "Amazon Linux*"
root_device_name = "/dev/xvda"

images = boto3.client("ec2").describe_images(
Filters=[
{"Name": "description", "Values": [image_prefix]},
{"Name": "architecture", "Values": ["arm64"]},
{
"Name": "architecture",
"Values": ["x86_64"],
}, # t3 instances are only compatible with x86 architecture
{
"Name": "root-device-type",
"Values": ["ebs"],
}, # instances which are capable of hibernation need to use an EBS-backed AMI
{"Name": "root-device-name", "Values": [root_device_name]},
],
Owners=["amazon"],
)
Expand Down Expand Up @@ -97,7 +106,7 @@ def parse_response(instance_ids: list):
image_id = get_latest_ami_id()

config = {
"InstanceType": "t4g.micro",
"InstanceType": "t3.micro",
"KeyName": key_name,
"TagSpecifications": [
{"ResourceType": "instance", "Tags": [{"Key": "Name", "Value": instance_name}]}
Expand All @@ -106,6 +115,9 @@ def parse_response(instance_ids: list):
# https://docs.aws.amazon.com/AWSEC2/latest/UserGuide/configuring-instance-metadata-service.html
"MetadataOptions": {"HttpEndpoint": "enabled", "HttpTokens": "required"},
"HibernationOptions": {"Configured": True},
"BlockDeviceMappings": [
{"DeviceName": "/dev/xvda", "Ebs": {"Encrypted": True, "DeleteOnTermination": True}}
],
}

# EC2CreateInstanceOperator creates and starts the EC2 instances. To test the EC2StartInstanceOperator,
Expand Down Expand Up @@ -151,13 +163,16 @@ def parse_response(instance_ids: list):
instance_ids=instance_id,
)
# [END howto_operator_ec2_reboot_instance]
reboot_instance.wait_for_completion = True

# [START howto_operator_ec2_hibernate_instance]
hibernate_instance = EC2HibernateInstanceOperator(
task_id="hibernate_instace",
instance_ids=instance_id,
)
# [END howto_operator_ec2_hibernate_instance]
hibernate_instance.wait_for_completion = True
hibernate_instance.max_attempts = 75

# [START howto_operator_ec2_terminate_instance]
terminate_instance = EC2TerminateInstanceOperator(
Expand Down