# Buggy code
def validate_arguments(self, args):
    """
    Validates command line arguments using the retrieved information.
    """

    if args.hostname:
        instances = self.opsworks.describe_instances(StackId=self._stack["StackId"])[
            "Instances"
        ]
        if any(args.hostname.lower() == instance["Hostname"] for instance in instances):
            raise ValueError(
                "Invalid hostname: '%s'. Hostnames must be unique within "
                "a stack." % args.hostname
            )

    if args.infrastructure_class == "ec2" and args.local:
        # make sure the regions match
        region = json.loads(urlopen(IDENTITY_URL).read())["region"]
        if region != self._stack["Region"]:
            raise ValueError("The stack's and the instance's region must match.")


# Traceback (TypeError)
aws --debug opsworks register --infrastructure-class ec2 --override-hostname 'somehostname' --region us-east-1 --stack-id 'some-stack-id' --local --use-instance-profile
2016-10-22 18:05:56,267 - MainThread - awscli.clidriver - DEBUG - CLI version: aws-cli/1.11.8 Python/3.5.2 Linux/4.4.0-45-generic botocore/1.4.65
2016-10-22 18:05:56,267 - MainThread - awscli.clidriver - DEBUG - Arguments entered to CLI: ['--debug', 'opsworks', 'register', '--infrastructure-class', 'ec2', '--override-hostname', 'somehostname', '--region', 'us-east-1', '--stack-id', 'some-stack-id', '--local', '--use-instance-profile']
2016-10-22 18:05:56,268 - MainThread - botocore.hooks - DEBUG - Event session-initialized: calling handler <function add_scalar_parsers at 0x7f10955af8c8>
2016-10-22 18:05:56,268 - MainThread - botocore.hooks - DEBUG - Event session-initialized: calling handler <function inject_assume_role_provider_cache at 0x7f109443b1e0>
2016-10-22 18:05:56,268 - MainThread - botocore.credentials - DEBUG - Skipping environment variable credential check because profile name was explicitly set.
2016-10-22 18:05:56,269 - MainThread - botocore.loaders - DEBUG - Loading JSON file: /usr/local/lib/python3.5/dist-packages/botocore/data/opsworks/2013-02-18/service-2.json
2016-10-22 18:05:56,274 - MainThread - botocore.hooks - DEBUG - Event service-data-loaded.opsworks: calling handler <function register_retries_for_service at 0x7f109481d840>
2016-10-22 18:05:56,275 - MainThread - botocore.handlers - DEBUG - Registering retry handlers for service: opsworks
2016-10-22 18:05:56,276 - MainThread - botocore.hooks - DEBUG - Event building-command-table.opsworks: calling handler <function inject_commands at 0x7f1094040ea0>
2016-10-22 18:05:56,277 - MainThread - botocore.hooks - DEBUG - Event building-command-table.opsworks: calling handler <function add_waiters at 0x7f10955b5c80>
2016-10-22 18:05:56,278 - MainThread - botocore.loaders - DEBUG - Loading JSON file: /usr/local/lib/python3.5/dist-packages/botocore/data/opsworks/2013-02-18/waiters-2.json
2016-10-22 18:05:56,279 - MainThread - botocore.hooks - DEBUG - Event building-command-table.register: calling handler <function add_waiters at 0x7f10955b5c80>
2016-10-22 18:05:56,280 - MainThread - botocore.hooks - DEBUG - Event load-cli-arg.custom.register.stack-id: calling handler <function uri_param at 0x7f109446ac80>
2016-10-22 18:05:56,280 - MainThread - botocore.hooks - DEBUG - Event process-cli-arg.custom.register: calling handler <awscli.argprocess.ParamShorthandParser object at 0x7f109447acc0>
2016-10-22 18:05:56,280 - MainThread - botocore.hooks - DEBUG - Event load-cli-arg.custom.register.anonymous: calling handler <function uri_param at 0x7f109446ac80>
2016-10-22 18:05:56,280 - MainThread - botocore.hooks - DEBUG - Event load-cli-arg.custom.register.anonymous: calling handler <function uri_param at 0x7f109446ac80>
2016-10-22 18:05:56,280 - MainThread - botocore.hooks - DEBUG - Event load-cli-arg.custom.register.anonymous: calling handler <function uri_param at 0x7f109446ac80>
2016-10-22 18:05:56,281 - MainThread - botocore.hooks - DEBUG - Event load-cli-arg.custom.register.target: calling handler <function uri_param at 0x7f109446ac80>
2016-10-22 18:05:56,281 - MainThread - botocore.hooks - DEBUG - Event load-cli-arg.custom.register.infrastructure-class: calling handler <function uri_param at 0x7f109446ac80>
2016-10-22 18:05:56,281 - MainThread - botocore.hooks - DEBUG - Event process-cli-arg.custom.register: calling handler <awscli.argprocess.ParamShorthandParser object at 0x7f109447acc0>
2016-10-22 18:05:56,281 - MainThread - botocore.hooks - DEBUG - Event load-cli-arg.custom.register.local: calling handler <function uri_param at 0x7f109446ac80>
2016-10-22 18:05:56,281 - MainThread - botocore.hooks - DEBUG - Event process-cli-arg.custom.register: calling handler <awscli.argprocess.ParamShorthandParser object at 0x7f109447acc0>
2016-10-22 18:05:56,281 - MainThread - botocore.hooks - DEBUG - Event load-cli-arg.custom.register.anonymous: calling handler <function uri_param at 0x7f109446ac80>
2016-10-22 18:05:56,281 - MainThread - botocore.hooks - DEBUG - Event load-cli-arg.custom.register.use-instance-profile: calling handler <function uri_param at 0x7f109446ac80>
2016-10-22 18:05:56,281 - MainThread - botocore.hooks - DEBUG - Event process-cli-arg.custom.register: calling handler <awscli.argprocess.ParamShorthandParser object at 0x7f109447acc0>
2016-10-22 18:05:56,281 - MainThread - botocore.hooks - DEBUG - Event load-cli-arg.custom.register.anonymous: calling handler <function uri_param at 0x7f109446ac80>
2016-10-22 18:05:56,282 - MainThread - botocore.hooks - DEBUG - Event load-cli-arg.custom.register.anonymous: calling handler <function uri_param at 0x7f109446ac80>
2016-10-22 18:05:56,282 - MainThread - botocore.credentials - DEBUG - Looking for credentials via: env
2016-10-22 18:05:56,282 - MainThread - botocore.credentials - DEBUG - Looking for credentials via: assume-role
2016-10-22 18:05:56,282 - MainThread - botocore.credentials - DEBUG - Looking for credentials via: shared-credentials-file
2016-10-22 18:05:56,282 - MainThread - botocore.credentials - DEBUG - Looking for credentials via: config-file
2016-10-22 18:05:56,282 - MainThread - botocore.credentials - DEBUG - Looking for credentials via: ec2-credentials-file
2016-10-22 18:05:56,282 - MainThread - botocore.credentials - DEBUG - Looking for credentials via: boto-config
2016-10-22 18:05:56,282 - MainThread - botocore.credentials - DEBUG - Looking for credentials via: container-role
2016-10-22 18:05:56,283 - MainThread - botocore.credentials - DEBUG - Looking for credentials via: iam-role
2016-10-22 18:05:56,286 - MainThread - botocore.vendored.requests.packages.urllib3.connectionpool - INFO - Starting new HTTP connection (1): 169.254.169.254
2016-10-22 18:05:56,287 - MainThread - botocore.vendored.requests.packages.urllib3.connectionpool - DEBUG - "GET /latest/meta-data/iam/security-credentials/ HTTP/1.1" 200 17
2016-10-22 18:05:56,289 - MainThread - botocore.vendored.requests.packages.urllib3.connectionpool - INFO - Starting new HTTP connection (1): 169.254.169.254
2016-10-22 18:05:56,290 - MainThread - botocore.vendored.requests.packages.urllib3.connectionpool - DEBUG - "GET /latest/meta-data/iam/security-credentials/openvpn-acme-test HTTP/1.1" 200 846
2016-10-22 18:05:56,290 - MainThread - botocore.credentials - INFO - Found credentials from IAM Role: openvpn-acme-test
2016-10-22 18:05:56,291 - MainThread - botocore.loaders - DEBUG - Loading JSON file: /usr/local/lib/python3.5/dist-packages/botocore/data/endpoints.json
2016-10-22 18:05:56,293 - MainThread - botocore.loaders - DEBUG - Loading JSON file: /usr/local/lib/python3.5/dist-packages/botocore/data/iam/2010-05-08/service-2.json
2016-10-22 18:05:56,300 - MainThread - botocore.client - DEBUG - Registering retry handlers for service: iam
2016-10-22 18:05:56,304 - MainThread - botocore.hooks - DEBUG - Event creating-client-class.iam: calling handler <function add_generate_presigned_url at 0x7f1094cc9b70>
2016-10-22 18:05:56,304 - MainThread - botocore.args - DEBUG - The s3 config key is not a dictionary type, ignoring its value of: None
2016-10-22 18:05:56,307 - MainThread - botocore.endpoint - DEBUG - Setting iam timeout as (60, 60)
2016-10-22 18:05:56,307 - MainThread - botocore.client - DEBUG - Registering retry handlers for service: opsworks
2016-10-22 18:05:56,309 - MainThread - botocore.hooks - DEBUG - Event creating-client-class.opsworks: calling handler <function add_generate_presigned_url at 0x7f1094cc9b70>
2016-10-22 18:05:56,309 - MainThread - botocore.args - DEBUG - The s3 config key is not a dictionary type, ignoring its value of: None
2016-10-22 18:05:56,311 - MainThread - botocore.endpoint - DEBUG - Setting opsworks timeout as (60, 60)
2016-10-22 18:05:56,311 - MainThread - awscli.customizations.opsworks - DEBUG - Retrieving stack and provisioning parameters
2016-10-22 18:05:56,312 - MainThread - botocore.endpoint - DEBUG - Making request for OperationModel(name=DescribeStacks) (verify_ssl=True) with params: {'url': 'https://opsworks.us-east-1.amazonaws.com/', 'method': 'POST', 'url_path': '/', 'query_string': '', 'context': {'client_region': 'us-east-1', 'has_streaming_input': False, 'client_config': <botocore.config.Config object at 0x7f1093c325c0>}, 'headers': {'User-Agent': 'aws-cli/1.11.8 Python/3.5.2 Linux/4.4.0-45-generic botocore/1.4.65', 'Content-Type': 'application/x-amz-json-1.1', 'X-Amz-Target': 'OpsWorks_20130218.DescribeStacks'}, 'body': b'{"StackIds": ["some-stack-id"]}'}
2016-10-22 18:05:56,312 - MainThread - botocore.hooks - DEBUG - Event request-created.opsworks.DescribeStacks: calling handler <bound method RequestSigner.handler of <botocore.signers.RequestSigner object at 0x7f1093c32550>>
2016-10-22 18:05:56,312 - MainThread - botocore.auth - DEBUG - Calculating signature using v4 auth.
2016-10-22 18:05:56,312 - MainThread - botocore.auth - DEBUG - CanonicalRequest:
POST
/

content-type:application/x-amz-json-1.1
host:opsworks.us-east-1.amazonaws.com
x-amz-date:20161022T180556Z
x-amz-security-token: some-token
x-amz-target:OpsWorks_20130218.DescribeStacks

content-type;host;x-amz-date;x-amz-security-token;x-amz-target
2bb6d9079ddc2fa0bb8fbf907d068de54083ba642ec1716e25ae9144e448fd33
2016-10-22 18:05:56,313 - MainThread - botocore.auth - DEBUG - StringToSign:
AWS4-HMAC-SHA256
20161022T180556Z
20161022/us-east-1/opsworks/aws4_request
bf2d221183683f7af42044ddfd0807ee49bf5fa822f65162ce75f8efb45c32a0
2016-10-22 18:05:56,313 - MainThread - botocore.auth - DEBUG - Signature:
6484214817d02cc9ca02450aea527c1c14eb00aafa476c177dc2edd7920f38da
2016-10-22 18:05:56,313 - MainThread - botocore.endpoint - DEBUG - Sending http request: <PreparedRequest [POST]>
2016-10-22 18:05:56,314 - MainThread - botocore.vendored.requests.packages.urllib3.connectionpool - INFO - Starting new HTTPS connection (1): opsworks.us-east-1.amazonaws.com
2016-10-22 18:05:56,429 - MainThread - botocore.vendored.requests.packages.urllib3.connectionpool - DEBUG - "POST / HTTP/1.1" 200 1106
2016-10-22 18:05:56,430 - MainThread - botocore.parsers - DEBUG - Response headers: {'content-type': 'application/x-amz-json-1.1', 'date': 'Sat, 22 Oct 2016 18:05:56 GMT', 'x-amzn-requestid': '2dd31f64-9882-11e6-8835-01c3aa973fc7', 'content-length': '1106'}
2016-10-22 18:05:56,430 - MainThread - botocore.parsers - DEBUG - Response body:
b'{"Stacks":[{"AgentVersion":"LATEST","Arn":"arn:aws:opsworks:us-east-1:some-aws-id:stack/some-stack-id/","Attributes":{"Color":null},"ChefConfiguration":{"BerkshelfVersion":"3.2.0","ManageBerkshelf":false},"ConfigurationManager":{"Name":"Chef","Version":"12"},"CreatedAt":"2016-10-22T17:08:38+00:00","CustomCookbooksSource":{"Type":"s3","Url":"http://cookbooks2-openvpn-acme-test.s3-website-us-east-1.amazonaws.com/chef/stacks/networking/cookbooks.zip"},"CustomJson":"{}","DefaultAvailabilityZone":"us-east-1a","DefaultInstanceProfileArn":"arn:aws:iam::some-aws-id:instance-profile/ec2-infrastructure-openvpn-acme-test","DefaultOs":"Ubuntu 16.04 LTS","DefaultRootDeviceType":"instance-store","DefaultSshKeyName":"openvpn-acme-test","DefaultSubnetId":"subnet-141d9e5d","HostnameTheme":"Layer_Dependent","Name":"infrastructure-openvpn-acme-test","Region":"us-east-1","ServiceRoleArn":"arn:aws:iam::some-aws-id:role/infrastructure-openvpn-acme-test","StackId":"some-stack-id","UseCustomCookbooks":true,"UseOpsworksSecurityGroups":false,"VpcId":"vpc-8fbeb0e8"}]}'
2016-10-22 18:05:56,431 - MainThread - botocore.hooks - DEBUG - Event needs-retry.opsworks.DescribeStacks: calling handler <botocore.retryhandler.RetryHandler object at 0x7f1093da9470>
2016-10-22 18:05:56,431 - MainThread - botocore.retryhandler - DEBUG - No retry needed.
2016-10-22 18:05:56,431 - MainThread - botocore.endpoint - DEBUG - Making request for OperationModel(name=DescribeStackProvisioningParameters) (verify_ssl=True) with params: {'url': 'https://opsworks.us-east-1.amazonaws.com/', 'method': 'POST', 'url_path': '/', 'query_string': '', 'context': {'client_region': 'us-east-1', 'has_streaming_input': False, 'client_config': <botocore.config.Config object at 0x7f1093c325c0>}, 'headers': {'User-Agent': 'aws-cli/1.11.8 Python/3.5.2 Linux/4.4.0-45-generic botocore/1.4.65', 'Content-Type': 'application/x-amz-json-1.1', 'X-Amz-Target': 'OpsWorks_20130218.DescribeStackProvisioningParameters'}, 'body': b'{"StackId": "some-stack-id"}'}
2016-10-22 18:05:56,431 - MainThread - botocore.hooks - DEBUG - Event request-created.opsworks.DescribeStackProvisioningParameters: calling handler <bound method RequestSigner.handler of <botocore.signers.RequestSigner object at 0x7f1093c32550>>
2016-10-22 18:05:56,432 - MainThread - botocore.auth - DEBUG - Calculating signature using v4 auth.
2016-10-22 18:05:56,432 - MainThread - botocore.auth - DEBUG - CanonicalRequest:
POST
/

content-type:application/x-amz-json-1.1
host:opsworks.us-east-1.amazonaws.com
x-amz-date:20161022T180556Z
x-amz-security-token:some-token
x-amz-target:OpsWorks_20130218.DescribeStackProvisioningParameters

content-type;host;x-amz-date;x-amz-security-token;x-amz-target
ccf31206ea969d241cc87b22035e2e3ad196d6c996ec070531b946fc65753d88
2016-10-22 18:05:56,432 - MainThread - botocore.auth - DEBUG - StringToSign:
AWS4-HMAC-SHA256
20161022T180556Z
20161022/us-east-1/opsworks/aws4_request
d9e2299fc5c70b002be0a7069931417b432f5e95a50c6f6b5f077af3c802dd01
2016-10-22 18:05:56,432 - MainThread - botocore.auth - DEBUG - Signature:
97edbd6285455316bbf83e77d0504c9af16d0ca8bac776accdaf91d7f29a8599
2016-10-22 18:05:56,433 - MainThread - botocore.endpoint - DEBUG - Sending http request: <PreparedRequest [POST]>
2016-10-22 18:05:56,550 - MainThread - botocore.vendored.requests.packages.urllib3.connectionpool - DEBUG - "POST / HTTP/1.1" 200 1287
2016-10-22 18:05:56,551 - MainThread - botocore.parsers - DEBUG - Response headers: {'content-type': 'application/x-amz-json-1.1', 'date': 'Sat, 22 Oct 2016 18:05:56 GMT', 'x-amzn-requestid': '2de2af8d-9882-11e6-954b-3362066917b5', 'content-length': '1287'}
2016-10-22 18:05:56,551 - MainThread - botocore.parsers - DEBUG - Response body:
b'{"AgentInstallerUrl":"https://opsworks-instance-agent-us-east-1.s3.amazonaws.com/4018-20160825092619/opsworks-agent-installer.tgz","Parameters":{"agent_installer_base_url":"https://opsworks-instance-agent-us-east-1.s3.amazonaws.com","agent_installer_tgz":"opsworks-agent-installer.tgz","assets_download_bucket":"opsworks-instance-assets-us-east-1.s3.amazonaws.com","charlie_public_key":"-----BEGIN PUBLIC KEY-----\\nMIIBIjANBgkqhkiG9w0BAQEFAAOCAQ8AMIIBCgKCAQEAni7eKdm34oaCvGiw96Fk\\nlyLX+aPfInYzilkk+AY3pXF6nijpQ2cm3ZeM2EoqZFTv3a/meosNBAs3Q3Sy1e4G\\n7Ibn/xwMof+iSBvimx3PGKFzNP0BhY9yS6AMEMxtmqksHb0glwmFeJcomdhxZV1F\\nziWTtL6ZEyvCg0I7rxGm1ceQmD25eK90VcZVh4LJtNfnwcZRM4eC+KK9Qllxw5hW\\nvB4Z52JMMZbEG9MYCLydWSY9rnVkAyQ0ngJUaJ3q7JsbkBV/J5BcrGgcbioR1k+h\\nINRoHwBQU9WnT/x8W+N6vwJb4o6v2hBR1H2GSDLwyZ7wC8EVH+XafWYpU1g/nSEe\\naQIDAQAB\\n-----END PUBLIC KEY-----","instance_service_endpoint":"opsworks-instance-service.us-east-1.amazonaws.com","instance_service_port":"443","instance_service_region":"us-east-1","instance_service_ssl_verify_peer":"true","instance_service_use_ssl":"true","ops_works_endpoint":"opsworks.us-east-1.amazonaws.com","ops_works_port":"443","ops_works_region":"us-east-1","ops_works_ssl_verify_peer":"true","ops_works_use_ssl":"true","verbose":"false","wait_between_runs":"30"}}'
2016-10-22 18:05:56,552 - MainThread - botocore.hooks - DEBUG - Event needs-retry.opsworks.DescribeStackProvisioningParameters: calling handler <botocore.retryhandler.RetryHandler object at 0x7f1093da9470>
2016-10-22 18:05:56,552 - MainThread - botocore.retryhandler - DEBUG - No retry needed.
2016-10-22 18:05:56,552 - MainThread - botocore.endpoint - DEBUG - Making request for OperationModel(name=DescribeInstances) (verify_ssl=True) with params: {'url': 'https://opsworks.us-east-1.amazonaws.com/', 'method': 'POST', 'url_path': '/', 'query_string': '', 'context': {'client_region': 'us-east-1', 'has_streaming_input': False, 'client_config': <botocore.config.Config object at 0x7f1093c325c0>}, 'headers': {'User-Agent': 'aws-cli/1.11.8 Python/3.5.2 Linux/4.4.0-45-generic botocore/1.4.65', 'Content-Type': 'application/x-amz-json-1.1', 'X-Amz-Target': 'OpsWorks_20130218.DescribeInstances'}, 'body': b'{"StackId": "some-stack-id"}'}
2016-10-22 18:05:56,552 - MainThread - botocore.hooks - DEBUG - Event request-created.opsworks.DescribeInstances: calling handler <bound method RequestSigner.handler of <botocore.signers.RequestSigner object at 0x7f1093c32550>>
2016-10-22 18:05:56,553 - MainThread - botocore.auth - DEBUG - Calculating signature using v4 auth.
2016-10-22 18:05:56,553 - MainThread - botocore.auth - DEBUG - CanonicalRequest:
POST
/

content-type:application/x-amz-json-1.1
host:opsworks.us-east-1.amazonaws.com
x-amz-date:20161022T180556Z
x-amz-security-token:some-token
x-amz-target:OpsWorks_20130218.DescribeInstances

content-type;host;x-amz-date;x-amz-security-token;x-amz-target
ccf31206ea969d241cc87b22035e2e3ad196d6c996ec070531b946fc65753d88
2016-10-22 18:05:56,553 - MainThread - botocore.auth - DEBUG - StringToSign:
AWS4-HMAC-SHA256
20161022T180556Z
20161022/us-east-1/opsworks/aws4_request
a30847fe72cbf9f6a813d492fbf1e6fb30a36d9a76bd1ba43e38db982b03c429
2016-10-22 18:05:56,553 - MainThread - botocore.auth - DEBUG - Signature:
b658ca9d578704199b5d528aa3bda0bbee78f3d82e3cce5b06c940ff8b2f6834
2016-10-22 18:05:56,553 - MainThread - botocore.endpoint - DEBUG - Sending http request: <PreparedRequest [POST]>
2016-10-22 18:05:56,665 - MainThread - botocore.vendored.requests.packages.urllib3.connectionpool - DEBUG - "POST / HTTP/1.1" 200 16
2016-10-22 18:05:56,666 - MainThread - botocore.parsers - DEBUG - Response headers: {'content-type': 'application/x-amz-json-1.1', 'date': 'Sat, 22 Oct 2016 18:05:55 GMT', 'x-amzn-requestid': '2df52610-9882-11e6-9c94-bbbf2061570e', 'content-length': '16'}
2016-10-22 18:05:56,666 - MainThread - botocore.parsers - DEBUG - Response body:
b'{"Instances":[]}'
2016-10-22 18:05:56,666 - MainThread - botocore.hooks - DEBUG - Event needs-retry.opsworks.DescribeInstances: calling handler <botocore.retryhandler.RetryHandler object at 0x7f1093da9470>
2016-10-22 18:05:56,666 - MainThread - botocore.retryhandler - DEBUG - No retry needed.
2016-10-22 18:05:56,669 - MainThread - awscli.clidriver - DEBUG - Exception caught in main()
Traceback (most recent call last):
File "/usr/local/lib/python3.5/dist-packages/awscli/clidriver.py", line 186, in main
return command_table[parsed_args.command](remaining, parsed_args)
File "/usr/local/lib/python3.5/dist-packages/awscli/clidriver.py", line 381, in __call__
return command_table[parsed_args.operation](remaining, parsed_globals)
File "/usr/local/lib/python3.5/dist-packages/awscli/customizations/commands.py", line 187, in __call__
return self._run_main(parsed_args, parsed_globals)
File "/usr/local/lib/python3.5/dist-packages/awscli/customizations/opsworks.py", line 144, in _run_main
self.validate_arguments(args)
File "/usr/local/lib/python3.5/dist-packages/awscli/customizations/opsworks.py", line 281, in validate_arguments
region = json.loads(urlopen(IDENTITY_URL).read())['region']
File "/usr/lib/python3.5/json/__init__.py", line 312, in loads
s.__class__.__name__))
TypeError: the JSON object must be str, not 'bytes'
2016-10-22 18:05:56,671 - MainThread - awscli.clidriver - DEBUG - Exiting with rc 255

the JSON object must be str, not 'bytes'

# Fixed code
def validate_arguments(self, args):
    """
    Validates command line arguments using the retrieved information.
    """

    if args.hostname:
        instances = self.opsworks.describe_instances(StackId=self._stack["StackId"])[
            "Instances"
        ]
        if any(args.hostname.lower() == instance["Hostname"] for instance in instances):
            raise ValueError(
                "Invalid hostname: '%s'. Hostnames must be unique within "
                "a stack." % args.hostname
            )

    if args.infrastructure_class == "ec2" and args.local:
        # make sure the regions match
        region = json.loads(ensure_text_type(urlopen(IDENTITY_URL).read()))["region"]
        if region != self._stack["Region"]:
            raise ValueError("The stack's and the instance's region must match.")