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

Upgrade boto to boto3 in deployment scripts #1377

Merged
merged 2 commits into from
Feb 29, 2024
Merged
Show file tree
Hide file tree
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
34 changes: 22 additions & 12 deletions deployment/cloudformation/privatehostedzone.py
Original file line number Diff line number Diff line change
@@ -1,9 +1,8 @@
from boto import route53

from majorkirby import CustomActionNode

import json

import boto3
import uuid

class R53PrivateHostedZone(CustomActionNode):
"""Represents a Route53 private hosted zone"""
Expand All @@ -19,21 +18,32 @@ class R53PrivateHostedZone(CustomActionNode):

def action(self):
"""Creates the zone"""
conn = route53.connect_to_region(self.REGION)
client = boto3.client('route53', region_name=self.REGION)
comment = json.dumps(self.get_raw_tags())

hosted_zones = conn.get_all_hosted_zones()
hosted_zones = client.list_hosted_zones()

for hosted_zone in hosted_zones['ListHostedZonesResponse']['HostedZones']:
for hosted_zone in hosted_zones['HostedZones']:
if ('Comment' in hosted_zone['Config'] and
hosted_zone['Config']['Comment'] == comment):
self.stack_outputs = {'PrivateHostedZoneId': hosted_zone['Id'].split('/')[-1]}
return

hosted_zone = conn.create_hosted_zone(self.get_input('PrivateHostedZoneName'),
comment=comment,
private_zone=True,
vpc_id=self.get_input('VpcId'),
vpc_region=self.REGION)

vpc_config = {
'VPCRegion': self.REGION,
'VPCId': self.get_input("VpcId")
}
hosted_zone_config = {
'Comment': comment,
'PrivateZone': True
}

hosted_zone = client.create_hosted_zone(
Name=self.get_input("PrivateHostedZoneName"),
CallerReference=str(uuid.uuid4()),
Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This method in boto had CallerReference (caller_ref) as an optional parameter and it would generate a Type 4 UUID to use by default. It is now required in boto3 and can be any unique string, so I'm continuing to use uuid by default here.

HostedZoneConfig=hosted_zone_config,
VPC=vpc_config,
)
hosted_zone_id = hosted_zone['CreateHostedZoneResponse']['HostedZone']['Id']
self.stack_outputs = {'PrivateHostedZoneId': hosted_zone_id.split('/')[-1]}

11 changes: 5 additions & 6 deletions deployment/cloudformation/utils/cfn.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
"""Helper functions and classes for dealing with cloudformation"""
import boto
import boto3


class AvailabilityZone(object):
Expand All @@ -15,7 +15,6 @@ def __init__(self, availability_zone):
Args:
availability_zone (AvailabilityZone): boto object
"""

self.availability_zone = availability_zone

@property
Expand All @@ -24,12 +23,12 @@ def cfn_name(self):
Utility method to return a string appropriate for CloudFormation
name of a resource (e.g. UsEast1a)
"""
return self.availability_zone.name.title().replace('-', '')
return self.availability_zone['ZoneName'].title().replace('-', '')

@property
def name(self):
"""Utility function to return the name of an availability zone (e.g. us-east-1a)"""
return self.availability_zone.name
return self.availability_zone['ZoneName']


def get_availability_zones():
Expand All @@ -38,5 +37,5 @@ def get_availability_zones():
Returns:
(list of AvailabilityZone): List of availability zones for a given EC2 region
"""
conn = boto.connect_ec2()
return [AvailabilityZone(az) for az in conn.get_all_zones()]
client = boto3.client('ec2', region_name='us-east-1')
return [AvailabilityZone(az) for az in client.describe_availability_zones()['AvailabilityZones']]
3 changes: 2 additions & 1 deletion python/cac_tripplanner/deployment_requirements.txt
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
boto==2.49.0
boto3==1.15.9
PyYAML==5.3.1
majorkirby==1.0.0
requests==2.24.0
troposphere==3.2.2
uuid==1.30.0