How to use create_internet_gateway method in localstack

Best Python code snippet using localstack_python

test_internet_gateways.py

Source:test_internet_gateways.py Github

copy

Full Screen

...16 """ internet gateway create """17 conn = boto.connect_vpc("the_key", "the_secret")18 conn.get_all_internet_gateways().should.have.length_of(0)19 with assert_raises(EC2ResponseError) as ex:20 igw = conn.create_internet_gateway(dry_run=True)21 ex.exception.error_code.should.equal("DryRunOperation")22 ex.exception.status.should.equal(400)23 ex.exception.message.should.equal(24 "An error occurred (DryRunOperation) when calling the CreateInternetGateway operation: Request would have succeeded, but DryRun flag is set"25 )26 igw = conn.create_internet_gateway()27 conn.get_all_internet_gateways().should.have.length_of(1)28 igw.id.should.match(r"igw-[0-9a-f]+")29 igw = conn.get_all_internet_gateways()[0]30 igw.attachments.should.have.length_of(0)31@mock_ec2_deprecated32def test_igw_attach():33 """ internet gateway attach """34 conn = boto.connect_vpc("the_key", "the_secret")35 igw = conn.create_internet_gateway()36 vpc = conn.create_vpc(VPC_CIDR)37 with assert_raises(EC2ResponseError) as ex:38 conn.attach_internet_gateway(igw.id, vpc.id, dry_run=True)39 ex.exception.error_code.should.equal("DryRunOperation")40 ex.exception.status.should.equal(400)41 ex.exception.message.should.equal(42 "An error occurred (DryRunOperation) when calling the AttachInternetGateway operation: Request would have succeeded, but DryRun flag is set"43 )44 conn.attach_internet_gateway(igw.id, vpc.id)45 igw = conn.get_all_internet_gateways()[0]46 igw.attachments[0].vpc_id.should.be.equal(vpc.id)47@mock_ec2_deprecated48def test_igw_attach_bad_vpc():49 """ internet gateway fail to attach w/ bad vpc """50 conn = boto.connect_vpc("the_key", "the_secret")51 igw = conn.create_internet_gateway()52 with assert_raises(EC2ResponseError) as cm:53 conn.attach_internet_gateway(igw.id, BAD_VPC)54 cm.exception.code.should.equal("InvalidVpcID.NotFound")55 cm.exception.status.should.equal(400)56 cm.exception.request_id.should_not.be.none57@mock_ec2_deprecated58def test_igw_attach_twice():59 """ internet gateway fail to attach twice """60 conn = boto.connect_vpc("the_key", "the_secret")61 igw = conn.create_internet_gateway()62 vpc1 = conn.create_vpc(VPC_CIDR)63 vpc2 = conn.create_vpc(VPC_CIDR)64 conn.attach_internet_gateway(igw.id, vpc1.id)65 with assert_raises(EC2ResponseError) as cm:66 conn.attach_internet_gateway(igw.id, vpc2.id)67 cm.exception.code.should.equal("Resource.AlreadyAssociated")68 cm.exception.status.should.equal(400)69 cm.exception.request_id.should_not.be.none70@mock_ec2_deprecated71def test_igw_detach():72 """ internet gateway detach"""73 conn = boto.connect_vpc("the_key", "the_secret")74 igw = conn.create_internet_gateway()75 vpc = conn.create_vpc(VPC_CIDR)76 conn.attach_internet_gateway(igw.id, vpc.id)77 with assert_raises(EC2ResponseError) as ex:78 conn.detach_internet_gateway(igw.id, vpc.id, dry_run=True)79 ex.exception.error_code.should.equal("DryRunOperation")80 ex.exception.status.should.equal(400)81 ex.exception.message.should.equal(82 "An error occurred (DryRunOperation) when calling the DetachInternetGateway operation: Request would have succeeded, but DryRun flag is set"83 )84 conn.detach_internet_gateway(igw.id, vpc.id)85 igw = conn.get_all_internet_gateways()[0]86 igw.attachments.should.have.length_of(0)87@mock_ec2_deprecated88def test_igw_detach_wrong_vpc():89 """ internet gateway fail to detach w/ wrong vpc """90 conn = boto.connect_vpc("the_key", "the_secret")91 igw = conn.create_internet_gateway()92 vpc1 = conn.create_vpc(VPC_CIDR)93 vpc2 = conn.create_vpc(VPC_CIDR)94 conn.attach_internet_gateway(igw.id, vpc1.id)95 with assert_raises(EC2ResponseError) as cm:96 conn.detach_internet_gateway(igw.id, vpc2.id)97 cm.exception.code.should.equal("Gateway.NotAttached")98 cm.exception.status.should.equal(400)99 cm.exception.request_id.should_not.be.none100@mock_ec2_deprecated101def test_igw_detach_invalid_vpc():102 """ internet gateway fail to detach w/ invalid vpc """103 conn = boto.connect_vpc("the_key", "the_secret")104 igw = conn.create_internet_gateway()105 vpc = conn.create_vpc(VPC_CIDR)106 conn.attach_internet_gateway(igw.id, vpc.id)107 with assert_raises(EC2ResponseError) as cm:108 conn.detach_internet_gateway(igw.id, BAD_VPC)109 cm.exception.code.should.equal("Gateway.NotAttached")110 cm.exception.status.should.equal(400)111 cm.exception.request_id.should_not.be.none112@mock_ec2_deprecated113def test_igw_detach_unattached():114 """ internet gateway fail to detach unattached """115 conn = boto.connect_vpc("the_key", "the_secret")116 igw = conn.create_internet_gateway()117 vpc = conn.create_vpc(VPC_CIDR)118 with assert_raises(EC2ResponseError) as cm:119 conn.detach_internet_gateway(igw.id, vpc.id)120 cm.exception.code.should.equal("Gateway.NotAttached")121 cm.exception.status.should.equal(400)122 cm.exception.request_id.should_not.be.none123@mock_ec2_deprecated124def test_igw_delete():125 """ internet gateway delete"""126 conn = boto.connect_vpc("the_key", "the_secret")127 vpc = conn.create_vpc(VPC_CIDR)128 conn.get_all_internet_gateways().should.have.length_of(0)129 igw = conn.create_internet_gateway()130 conn.get_all_internet_gateways().should.have.length_of(1)131 with assert_raises(EC2ResponseError) as ex:132 conn.delete_internet_gateway(igw.id, dry_run=True)133 ex.exception.error_code.should.equal("DryRunOperation")134 ex.exception.status.should.equal(400)135 ex.exception.message.should.equal(136 "An error occurred (DryRunOperation) when calling the DeleteInternetGateway operation: Request would have succeeded, but DryRun flag is set"137 )138 conn.delete_internet_gateway(igw.id)139 conn.get_all_internet_gateways().should.have.length_of(0)140@mock_ec2_deprecated141def test_igw_delete_attached():142 """ internet gateway fail to delete attached """143 conn = boto.connect_vpc("the_key", "the_secret")144 igw = conn.create_internet_gateway()145 vpc = conn.create_vpc(VPC_CIDR)146 conn.attach_internet_gateway(igw.id, vpc.id)147 with assert_raises(EC2ResponseError) as cm:148 conn.delete_internet_gateway(igw.id)149 cm.exception.code.should.equal("DependencyViolation")150 cm.exception.status.should.equal(400)151 cm.exception.request_id.should_not.be.none152@mock_ec2_deprecated153def test_igw_desribe():154 """ internet gateway fetch by id """155 conn = boto.connect_vpc("the_key", "the_secret")156 igw = conn.create_internet_gateway()157 igw_by_search = conn.get_all_internet_gateways([igw.id])[0]158 igw.id.should.equal(igw_by_search.id)159@mock_ec2_deprecated160def test_igw_describe_bad_id():161 """ internet gateway fail to fetch by bad id """162 conn = boto.connect_vpc("the_key", "the_secret")163 with assert_raises(EC2ResponseError) as cm:164 conn.get_all_internet_gateways([BAD_IGW])165 cm.exception.code.should.equal("InvalidInternetGatewayID.NotFound")166 cm.exception.status.should.equal(400)167 cm.exception.request_id.should_not.be.none168@mock_ec2_deprecated169def test_igw_filter_by_vpc_id():170 """ internet gateway filter by vpc id """171 conn = boto.connect_vpc("the_key", "the_secret")172 igw1 = conn.create_internet_gateway()173 igw2 = conn.create_internet_gateway()174 vpc = conn.create_vpc(VPC_CIDR)175 conn.attach_internet_gateway(igw1.id, vpc.id)176 result = conn.get_all_internet_gateways(filters={"attachment.vpc-id": vpc.id})177 result.should.have.length_of(1)178 result[0].id.should.equal(igw1.id)179@mock_ec2_deprecated180def test_igw_filter_by_tags():181 """ internet gateway filter by vpc id """182 conn = boto.connect_vpc("the_key", "the_secret")183 igw1 = conn.create_internet_gateway()184 igw2 = conn.create_internet_gateway()185 igw1.add_tag("tests", "yes")186 result = conn.get_all_internet_gateways(filters={"tag:tests": "yes"})187 result.should.have.length_of(1)188 result[0].id.should.equal(igw1.id)189@mock_ec2_deprecated190def test_igw_filter_by_internet_gateway_id():191 """ internet gateway filter by internet gateway id """192 conn = boto.connect_vpc("the_key", "the_secret")193 igw1 = conn.create_internet_gateway()194 igw2 = conn.create_internet_gateway()195 result = conn.get_all_internet_gateways(filters={"internet-gateway-id": igw1.id})196 result.should.have.length_of(1)197 result[0].id.should.equal(igw1.id)198@mock_ec2_deprecated199def test_igw_filter_by_attachment_state():200 """ internet gateway filter by attachment state """201 conn = boto.connect_vpc("the_key", "the_secret")202 igw1 = conn.create_internet_gateway()203 igw2 = conn.create_internet_gateway()204 vpc = conn.create_vpc(VPC_CIDR)205 conn.attach_internet_gateway(igw1.id, vpc.id)206 result = conn.get_all_internet_gateways(filters={"attachment.state": "available"})207 result.should.have.length_of(1)208 result[0].id.should.equal(igw1.id)209@mock_ec2210def test_create_internet_gateway_with_tags():211 ec2 = boto3.resource("ec2", region_name="eu-central-1")212 igw = ec2.create_internet_gateway(213 TagSpecifications=[214 {215 "ResourceType": "internet-gateway",216 "Tags": [{"Key": "test", "Value": "TestRouteTable"}],217 }218 ],219 )220 igw.tags.should.have.length_of(1)...

Full Screen

Full Screen

igw.py

Source:igw.py Github

copy

Full Screen

...4 aws_secret_access_key='Zo3u7dchqBg6hoZg2jRp0JmeilFvWlbBCc5HVCQN',5 region_name='eu-west-2')6ec2client = boto3.client('ec2')7ec2resource = boto3.resource('ec2')8response = ec2client.create_internet_gateway()9newigwid = response["InternetGateway"]["InternetGatewayId"]10newigw = ec2resource.InternetGateway(newigwid)11# new_igw_object = ec2resource.create_internet_gateway()12# newigw.attach_to_vpc(13# VpcId=newvpcid...

Full Screen

Full Screen

Automation Testing Tutorials

Learn to execute automation testing from scratch with LambdaTest Learning Hub. Right from setting up the prerequisites to run your first automation test, to following best practices and diving deeper into advanced test scenarios. LambdaTest Learning Hubs compile a list of step-by-step guides to help you be proficient with different test automation frameworks i.e. Selenium, Cypress, TestNG etc.

LambdaTest Learning Hubs:

YouTube

You could also refer to video tutorials over LambdaTest YouTube channel to get step by step demonstration from industry experts.

Run localstack automation tests on LambdaTest cloud grid

Perform automation testing on 3000+ real desktop and mobile devices online.

Try LambdaTest Now !!

Get 100 minutes of automation test minutes FREE!!

Next-Gen App & Browser Testing Cloud

Was this article helpful?

Helpful

NotHelpful