How to use create_rest_resource method in localstack

Best Python code snippet using localstack_python

GayatriOrganicsREST_API.py

Source: GayatriOrganicsREST_API.py Github

copy

Full Screen

...23 self.rest_api_id = response.get('id', '')24 else:25 self.rest_api_id = rest_api_id26 self.resource_path_ids = get_resource_path(self.rest_api_id)27 def create_rest_resource(self, rest_resource_details):28 try:29 response = api_gateway.create_resource(**rest_resource_details)30 self.resource_path_ids[response['path']] = response['id']31 except Exception as e:32 print(e)33 def create_method_request(self, method_details):34 try:35 api_gateway.put_method(**method_details)36 except Exception as e:37 print("method_request",e)38 def create_method_response(self, method_details):39 try:40 api_gateway.put_method_response(**method_details)41 except Exception as e:42 print("method_response",e)43 def create_integration_request(self, integration_details):44 try:45 api_gateway.put_integration(**integration_details)46 except Exception as e:47 print("integration_request",e)48 def create_integration_response(self, integration_response_details):49 try:50 api_gateway.put_integration_response(**integration_response_details)51 except Exception as e:52 print("integration_response",e)53 def deploy(self,deploy_details):54 try:55 api_gateway.create_deployment(**deploy_details)56 except Exception as e:57 print(e)58if __name__ == '__main__':59 uri = 'arn:aws:apigateway:ap-south-1:dynamodb:action/​{}'60 credentials = 'arn:aws:iam::980367155655:role/​api_gateway_dynamodb'61 table_name = 'GayatriOrganicStores'62 # Creating rest_api SriGayatriOrganicsNew63 rest_api_creation_details = {64 'name': 'SriGayatriOrganicsNew',65 'description': "This api is for testing purposes",66 'version': 'v1',67 'endpointConfiguration': {'types': ['REGIONAL']}68 }69 rest_api_gateway = RESTApiGateway(rest_api_creation_details)70 sri_gayatri_organic_stores = dict()71 # Creating resource /​srigayatriorganicstores72 path = '/​srigayatriorganicstores'73 sri_gayatri_organic_stores[path] = {74 'restApiId': rest_api_gateway.rest_api_id,75 'parentId': rest_api_gateway.resource_path_ids['/​'],76 'pathPart': 'srigayatriorganicstores'77 }78 rest_api_gateway.create_rest_resource(sri_gayatri_organic_stores[path])79 # Creating methods in /​srigayatriorganicstores80 # Creating GET method_request81 sri_gayatri_organic_stores[path]['GET'] = {"method_request": {82 'restApiId': rest_api_gateway.rest_api_id,83 'resourceId': rest_api_gateway.resource_path_ids[path],84 'httpMethod': 'GET',85 'authorizationType': 'NONE'86 }}87 rest_api_gateway.create_method_request(sri_gayatri_organic_stores.get88 (path).get('GET').get('method_request'))89 # Creating GET method_response90 sri_gayatri_organic_stores[path]['GET'] = {"method_response": {91 'restApiId': rest_api_gateway.rest_api_id,92 'resourceId': rest_api_gateway.resource_path_ids[path],93 'httpMethod': 'GET',94 'statusCode': '200'95 }}96 rest_api_gateway.create_method_response(sri_gayatri_organic_stores.get97 (path).get('GET').get('method_response'))98 # Creating GET integration_request99 sri_gayatri_organic_stores[path]['GET'] = {"integration_request": {100 'restApiId': rest_api_gateway.rest_api_id,101 'resourceId': rest_api_gateway.resource_path_ids[path],102 'httpMethod': 'GET',103 'type': 'AWS',104 'integrationHttpMethod': 'POST',105 'uri': uri.format('Scan'),106 'credentials': credentials,107 'requestTemplates': {'application/​json': json.dumps({108 'TableName': table_name,109 'ProjectionExpression': "StorePlace,StoreID"}110 )}111 }}112 rest_api_gateway.create_integration_request(113 sri_gayatri_organic_stores.get(path).get('GET').get('integration_request'))114 # Creating GET integration_response115 sri_gayatri_organic_stores[path]['GET'] = {"integration_response": {116 'restApiId': rest_api_gateway.rest_api_id,117 'resourceId': rest_api_gateway.resource_path_ids[path],118 'httpMethod': 'GET',119 'statusCode': '200',120 'responseTemplates': {'application/​json': ''}121 }}122 rest_api_gateway.create_integration_response(123 sri_gayatri_organic_stores.get(path).get('GET').get('integration_response'))124 # Creating sub resource /​srigayatriorganicstores/​{storeplace}125 path = '/​srigayatriorganicstores/​{storeplace}'126 sri_gayatri_organic_stores[path] = {127 'restApiId': rest_api_gateway.rest_api_id,128 'parentId': rest_api_gateway.resource_path_ids['/​srigayatriorganicstores'],129 'pathPart': '{storeplace}'130 }131 rest_api_gateway.create_rest_resource(sri_gayatri_organic_stores[path])132 # Creating methods in /​srigayatriorganicstores/​{storeplace}133 # Creating GET method_request134 sri_gayatri_organic_stores[path]['GET'] = {"method_request": {135 'restApiId': rest_api_gateway.rest_api_id,136 'resourceId': rest_api_gateway.resource_path_ids[path],137 'httpMethod': 'GET',138 'authorizationType': 'NONE'139 }}140 rest_api_gateway.create_method_request(sri_gayatri_organic_stores.get(path).get('GET').get('method_request'))141 # Creating GET method_response142 sri_gayatri_organic_stores[path]['GET'] = {"method_response": {143 'restApiId': rest_api_gateway.rest_api_id,144 'resourceId': rest_api_gateway.resource_path_ids[path],145 'httpMethod': 'GET',146 'statusCode': '200'147 }}148 rest_api_gateway.create_method_response(sri_gayatri_organic_stores.get149 (path).get('GET').get('method_response'))150 # Creating GET integration_request151 sri_gayatri_organic_stores[path]['GET'] = {"integration_request": {152 'restApiId': rest_api_gateway.rest_api_id,153 'resourceId': rest_api_gateway.resource_path_ids[path],154 'httpMethod': 'GET',155 'type': 'AWS',156 'integrationHttpMethod': 'POST',157 'uri': uri.format('Scan'),158 'credentials': credentials,159 'requestTemplates': {'application/​json': json.dumps({160 'TableName': table_name,161 'FilterExpression':'StorePlace= :storeplace',162 'ExpressionAttributeValues': {163 ':storeplace': {"S": "$input.params('storeplace')"}164 }165 }166 )}167 }}168 rest_api_gateway.create_integration_request(169 sri_gayatri_organic_stores.get(path).get('GET').get('integration_request'))170 # Creating GET integration_response171 sri_gayatri_organic_stores[path]['GET'] = {"integration_response": {172 'restApiId': rest_api_gateway.rest_api_id,173 'resourceId': rest_api_gateway.resource_path_ids[path],174 'httpMethod': 'GET',175 'statusCode': '200',176 'responseTemplates': {'application/​json': ''}177 }}178 rest_api_gateway.create_integration_response(179 sri_gayatri_organic_stores.get(path).get('GET').get('integration_response'))180 # Creating sub resource /​srigayatriorganicstores/​{storeplace}/​{storeid}181 path = '/​srigayatriorganicstores/​{storeplace}/​{storeid}'182 sri_gayatri_organic_stores[path] = {183 'restApiId': rest_api_gateway.rest_api_id,184 'parentId': rest_api_gateway.resource_path_ids['/​srigayatriorganicstores/​{storeplace}'],185 'pathPart': '{storeid}'186 }187 rest_api_gateway.create_rest_resource(sri_gayatri_organic_stores[path])188 # Creating methods in /​srigayatriorganicstores/​{storeplace}/​{storeid}189 # Creating GET method_request190 sri_gayatri_organic_stores[path]['GET'] = {"method_request": {191 'restApiId': rest_api_gateway.rest_api_id,192 'resourceId': rest_api_gateway.resource_path_ids[path],193 'httpMethod': 'GET',194 'authorizationType': 'NONE'195 }}196 rest_api_gateway.create_method_request(sri_gayatri_organic_stores.get(path).get('GET').get('method_request'))197 # Creating GET method_response198 sri_gayatri_organic_stores[path]['GET'] = {"method_response": {199 'restApiId': rest_api_gateway.rest_api_id,200 'resourceId': rest_api_gateway.resource_path_ids[path],201 'httpMethod': 'GET',...

Full Screen

Full Screen

test_apigateway_integrations.py

Source: test_apigateway_integrations.py Github

copy

Full Screen

...47 runtime=LAMBDA_RUNTIME_PYTHON39,48 )49 lambda_arn = aws_stack.lambda_function_arn(fn_name)50 api_id, _, root = create_rest_api(apigateway_client, name="aws lambda api")51 resource_id, _ = create_rest_resource(52 apigateway_client, restApiId=api_id, parentId=root, pathPart="test"53 )54 # create method and integration55 create_rest_resource_method(56 apigateway_client,57 restApiId=api_id,58 resourceId=resource_id,59 httpMethod="GET",60 authorizationType="NONE",61 )62 create_rest_api_integration(63 apigateway_client,64 restApiId=api_id,65 resourceId=resource_id,...

Full Screen

Full Screen

apigateway_fixtures.py

Source: apigateway_fixtures.py Github

copy

Full Screen

...39 assert_response_is_200(response)40def delete_rest_api(apigateway_client, **kwargs):41 response = apigateway_client.delete_rest_api(**kwargs)42 assert_response_status(response, 202)43def create_rest_resource(apigateway_client, **kwargs):44 response = apigateway_client.create_resource(**kwargs)45 assert_response_is_200(response)46 return response.get("id"), response.get("parentId")47def delete_rest_resource(apigateway_client, **kwargs):48 response = apigateway_client.delete_resource(**kwargs)49 assert_response_is_200(response)50def create_rest_resource_method(apigateway_client, **kwargs):51 response = apigateway_client.put_method(**kwargs)52 assert_response_is_200(response)53 return response.get("httpMethod"), response.get("authorizerId")54def create_rest_authorizer(apigateway_client, **kwargs):55 response = apigateway_client.create_authorizer(**kwargs)56 assert_response_is_200(response)57 return response.get("id"), response.get("type")...

Full Screen

Full Screen

Blogs

Check out the latest blogs from LambdaTest on this topic:

13 Best Java Testing Frameworks For 2023

The fact is not alien to us anymore that cross browser testing is imperative to enhance your application’s user experience. Enhanced knowledge of popular and highly acclaimed testing frameworks goes a long way in developing a new app. It holds more significance if you are a full-stack developer or expert programmer.

QA Innovation – Using the senseshaping concept to discover customer needs

QA Innovation - Using the senseshaping concept to discover customer needsQA testers have a unique role and responsibility to serve the customer. Serving the customer in software testing means protecting customers from application defects, failures, and perceived failures from missing or misunderstood requirements. Testing for known requirements based on documentation or discussion is the core of the testing profession. One unique way QA testers can both differentiate themselves and be innovative occurs when senseshaping is used to improve the application user experience.

Best 23 Web Design Trends To Follow In 2023

Having a good web design can empower business and make your brand stand out. According to a survey by Top Design Firms, 50% of users believe that website design is crucial to an organization’s overall brand. Therefore, businesses should prioritize website design to meet customer expectations and build their brand identity. Your website is the face of your business, so it’s important that it’s updated regularly as per the current web design trends.

Acquiring Employee Support for Change Management Implementation

Enterprise resource planning (ERP) is a form of business process management software—typically a suite of integrated applications—that assists a company in managing its operations, interpreting data, and automating various back-office processes. The introduction of a new ERP system is analogous to the introduction of a new product into the market. If the product is not handled appropriately, it will fail, resulting in significant losses for the business. Most significantly, the employees’ time, effort, and morale would suffer as a result of the procedure.

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