Best Python code snippet using localstack_python
tgw-peering-route-automation.py
Source:tgw-peering-route-automation.py  
...22##############23        print("printing dict2[region2] " +dict_2[region2])24        25        26        get_tgw_id1=tgwclient1.describe_transit_gateway_route_tables(27            TransitGatewayRouteTableIds=[28                            dict_1[region1],29                        ],30                        )31        tgwid1=get_tgw_id1['TransitGatewayRouteTables'][0]['TransitGatewayId']32        print(tgwid1)33        34        get_tgw_id2=tgwclient2.describe_transit_gateway_route_tables(35            TransitGatewayRouteTableIds=[36                            dict_2[region2],37                        ],38                        )39        tgwid2=get_tgw_id2['TransitGatewayRouteTables'][0]['TransitGatewayId']40        print(tgwid2)41##############Describe all peering attachments for each Dict_1 regions#######42        findattachment=tgwclient2.describe_transit_gateway_peering_attachments(43                    Filters=[44                        {45                            'Name': 'state',46                            'Values': [47                                'available',48                                        ]...test_transit_gateway_routetable.py
Source:test_transit_gateway_routetable.py  
1# Copyright (c) 2018 Cloudify Platform Ltd. All rights reserved2#3# Licensed under the Apache License, Version 2.0 (the "License");4# you may not use this file except in compliance with the License.5# You may obtain a copy of the License at6#7#        http://www.apache.org/licenses/LICENSE-2.08#9# Unless required by applicable law or agreed to in writing, software10# distributed under the License is distributed on an "AS IS" BASIS,11# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.12# See the License for the specific language governing permissions and13# limitations under the License.14# Standard imports15import unittest16# Third party imports17from mock import patch, MagicMock18# Local imports19from cloudify_aws.common._compat import reload_module20from cloudify_aws.common.tests.test_base import (21    TestBase,22    mock_decorator23)24from cloudify_aws.ec2.resources import transit_gateway_routetable as mod25class TestEC2RouteTable(TestBase):26    def setUp(self):27        self.routetable = mod.EC2TransitGatewayRouteTable(28            "ctx_node", resource_id=True, client=True, logger=None)29        mock1 = patch('cloudify_aws.common.decorators.aws_resource',30                      mock_decorator)31        mock2 = patch('cloudify_aws.common.decorators.wait_for_status',32                      mock_decorator)33        mock1.start()34        mock2.start()35        reload_module(mod)36    def test_class_properties(self):37        effect = self.get_client_error_exception(38            name='EC2 Transit Gateway Route Table')39        self.routetable.client = \40            self.make_client_function('describe_transit_gateway_route_tables',41                                      side_effect=effect)42        self.assertIsNone(self.routetable.properties)43        value = {}44        self.routetable.client = \45            self.make_client_function('describe_transit_gateway_route_tables',46                                      return_value=value)47        self.assertIsNone(self.routetable.properties)48        value = {mod.ROUTETABLES: [{mod.ROUTETABLE_ID: 'test_name'}]}49        self.routetable.client = \50            self.make_client_function('describe_transit_gateway_route_tables',51                                      return_value=value)52        res = self.routetable.properties53        self.assertEqual(res[mod.ROUTETABLE_ID], 'test_name')54    def test_class_create(self):55        value = {mod.ROUTETABLE: 'foo'}56        self.routetable.client = \57            self.make_client_function('create_transit_gateway_route_table',58                                      return_value=value)59        res = self.routetable.create(value)60        self.assertEqual(res[mod.ROUTETABLE], value[mod.ROUTETABLE])61    def test_class_delete(self):62        params = {}63        self.routetable.client = self.make_client_function(64            'delete_transit_gateway_route_table')65        self.routetable.delete(params)66        self.assertTrue(67            self.routetable.client.delete_transit_gateway_route_table.called)68        params = {mod.ROUTETABLE: 'foo'}69        self.routetable.delete(params)70        self.assertEqual(params[mod.ROUTETABLE], 'foo')71    def test_class_attach(self):72        value = {mod.ROUTETABLE_ID: 'foo', mod.TG_ATTACHMENT_ID: 'bar'}73        self.routetable.client = \74            self.make_client_function('associate_transit_gateway_route_table',75                                      return_value=value)76        res = self.routetable.attach(value)77        self.assertEqual(res[mod.ROUTETABLE_ID], value[mod.ROUTETABLE_ID])78    def test_class_detach(self):79        params = {}80        self.routetable.client = self.make_client_function(81            'disassociate_transit_gateway_route_table')82        self.routetable.detach(params)83        self.assertTrue(84            self.routetable.client85                .disassociate_transit_gateway_route_table.called)86        # ctx = self.get_mock_ctx("TransitGatewayRouteTable")87        params = {}88        self.routetable.detach(params)89        self.assertTrue(90            self.routetable.client91                .disassociate_transit_gateway_route_table.called)92    def test_create(self):93        ctx = self.get_mock_ctx("RouteTable")94        config = {mod.TG_ID: 'foo'}95        self.routetable.resource_id = 'foo'96        iface = MagicMock()97        iface.create = self.mock_return({mod.ROUTETABLE: config})98        mod.create(ctx=ctx, iface=iface, resource_config=config)99        self.assertEqual(self.routetable.resource_id, 'foo')100    def test_attach(self):101        ctx = self.get_mock_ctx("RouteTable")102        self.routetable.resource_id = 'foo'103        config = {mod.ROUTETABLE_ID: 'foo', mod.TG_ATTACHMENT_ID: 'bar'}104        iface = MagicMock()105        iface.attach = self.mock_return(config)106        with patch('cloudify_aws.common.utils.find_rel_by_node_type'):107            mod.attach(ctx, iface, config)108        self.assertEqual(self.routetable.resource_id,109                         'foo')110    def test_delete(self):111        ctx = self.get_mock_ctx("RouteTable")112        iface = MagicMock()113        mod.delete(ctx=ctx, iface=iface, resource_config={})114        self.assertTrue(iface.delete.called)115    def test_detach(self):116        ctx = self.get_mock_ctx("RouteTable")117        self.routetable.resource_id = 'route table'118        ctx.instance.runtime_properties['association_ids'] = ['association_id']119        iface = MagicMock()120        iface.detach = self.mock_return(ctx.instance.runtime_properties[121                                        'association_ids'])122        mod.detach(ctx, iface, {})123        self.assertEqual(self.routetable.resource_id,124                         'route table')125if __name__ == '__main__':...lambda-ssm.py
Source:lambda-ssm.py  
...95            Overwrite=True96        )9798    client = boto3.client('ec2')99    response = client.describe_transit_gateway_route_tables()100    # print(response)101    for tgwroutetable in client.describe_transit_gateway_route_tables()['TransitGatewayRouteTables']:102        tgwroutetableId = tgwroutetable['TransitGatewayRouteTableId']103        tgwroutetableName = tgwroutetable['Tags'][0]['Value']104        print(tgwroutetableId)105        print(tgwroutetableName)106107        client = boto3.client('ssm')108        response = client.put_parameter(109            Name=tgwroutetableName,110            Description='Name of your resource',111            Value=tgwroutetableId,112            Type='String',113            Overwrite=True
...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.
You could also refer to video tutorials over LambdaTest YouTube channel to get step by step demonstration from industry experts.
Get 100 minutes of automation test minutes FREE!!
