From 4fce4a877e64e0e36a8ace17ba4804296ebe4605 Mon Sep 17 00:00:00 2001 From: Vinicius Pereira Date: Tue, 26 Oct 2021 17:30:28 -0300 Subject: [PATCH 1/3] add CF template for the blog post --- blog-assets/template.yaml | 158 ++++++++++++++++++++++++++++++++++++++ 1 file changed, 158 insertions(+) create mode 100644 blog-assets/template.yaml diff --git a/blog-assets/template.yaml b/blog-assets/template.yaml new file mode 100644 index 0000000..81c3edd --- /dev/null +++ b/blog-assets/template.yaml @@ -0,0 +1,158 @@ +AWSTemplateFormatVersion: '2010-09-09' + +Description: AWS API Gateway working as a Service Virtualization + +Resources: + + RestApi: + Type: AWS::ApiGateway::RestApi + Properties: + ApiKeySourceType: HEADER + Description: An API Gateway as Service Virtualization + EndpointConfiguration: + Types: + - EDGE + Name: mock-api + + Resource: + Type: AWS::ApiGateway::Resource + Properties: + ParentId: !GetAtt RestApi.RootResourceId + PathPart: 'mock' + RestApiId: !Ref RestApi + + GetMethod: + Type: AWS::ApiGateway::Method + Properties: + ApiKeyRequired: false + AuthorizationType: NONE + HttpMethod: GET + RequestParameters: + method.request.querystring.method: true + MethodResponses: + - ResponseModels: + application/json: !Ref ApiGatewayModel + StatusCode: 200 + - ResponseModels: + application/json: !Ref ApiGatewayModel + StatusCode: 201 + - ResponseModels: + application/json: !Ref ApiGatewayModel + StatusCode: 500 + - ResponseModels: + application/json: !Ref ApiGatewayModel + StatusCode: 503 + Integration: + ConnectionType: INTERNET + IntegrationResponses: + - ResponseTemplates: + application/json: | + { + "statusCode": 200, + "message": "OK. No problem here." + } + StatusCode: 200 + - ResponseTemplates: + application/json: | + { + "statusCode": 201, + "message": "Created. It appears to be good." + } + SelectionPattern: '201' + StatusCode: 201 + - ResponseTemplates: + application/json: | + { + "statusCode": 500, + "message": "Internal Server Error. Houston, we have a problem." + } + SelectionPattern: '500' + StatusCode: 500 + - ResponseTemplates: + application/json: | + { + "statusCode": 503, + "message": "Service Unavailable. I am not ready yet." + } + SelectionPattern: '503' + StatusCode: 503 + PassthroughBehavior: WHEN_NO_TEMPLATES + RequestTemplates: + application/json: | + { + #if ( $input.params('method') == "ok" ) + "statusCode": 200 + #elseif ( $input.params('method') == "created" ) + "statusCode": 201 + #elseif ( $input.params('method') == "internalerror" ) + "statusCode": 500 + #else + "statusCode": 503 + #end + } + Type: MOCK + TimeoutInMillis: 29000 + OperationName: 'mock' + ResourceId: !Ref Resource + RestApiId: !Ref RestApi + + PostMethod: + Type: AWS::ApiGateway::Method + Properties: + ApiKeyRequired: false + AuthorizationType: NONE + HttpMethod: POST + MethodResponses: + - ResponseModels: + application/json: !Ref ApiGatewayModel + StatusCode: 200 + - ResponseModels: + application/json: !Ref ApiGatewayModel + StatusCode: 500 + Integration: + ConnectionType: INTERNET + IntegrationResponses: + - ResponseTemplates: + application/json: "{\"message\": \"OK. No problem here.\"}" + # SelectionPattern: '2\d{2}' + StatusCode: 200 + - ResponseTemplates: + application/json: "{\"message\": \"Internal Server Error. Houston, we have a problem.\"}" + SelectionPattern: '5\d{2}' + StatusCode: 500 + PassthroughBehavior: WHEN_NO_TEMPLATES + RequestTemplates: + application/json: | + { + "statusCode": $input.json('$.statusCode'), + "message": $input.json('$.message') + } + Type: MOCK + TimeoutInMillis: 29000 + OperationName: 'mock' + ResourceId: !Ref Resource + RestApiId: !Ref RestApi + + ApiGatewayModel: + Type: AWS::ApiGateway::Model + Properties: + ContentType: 'application/json' + RestApiId: !Ref RestApi + Schema: {} + + ApiGatewayStage: + Type: AWS::ApiGateway::Stage + Properties: + DeploymentId: !Ref ApiGatewayDeployment + Description: Mock API Stage v0 + RestApiId: !Ref RestApi + StageName: 'v0' + + ApiGatewayDeployment: + Type: AWS::ApiGateway::Deployment + DependsOn: + - GetMethod + - PostMethod + Properties: + Description: Mock API Deployment + RestApiId: !Ref RestApi \ No newline at end of file From 8e58afb9cf3b20a1a0f1556c86aa138b9651acc9 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Vin=C3=ADcius=20Pereira?= Date: Tue, 26 Oct 2021 17:43:37 -0300 Subject: [PATCH 2/3] add Postman collection for the blog post --- ...t.SVwithAPIGateway.postman_collection.json | 70 +++++++++++++++++++ 1 file changed, 70 insertions(+) create mode 100644 blog-assets/AWS Blog Post.SVwithAPIGateway.postman_collection.json diff --git a/blog-assets/AWS Blog Post.SVwithAPIGateway.postman_collection.json b/blog-assets/AWS Blog Post.SVwithAPIGateway.postman_collection.json new file mode 100644 index 0000000..28c018c --- /dev/null +++ b/blog-assets/AWS Blog Post.SVwithAPIGateway.postman_collection.json @@ -0,0 +1,70 @@ +{ + "info": { + "_postman_id": "233e8d84-5068-4909-84f0-c0340b451606", + "name": "AWS Blog Post", + "schema": "https://schema.getpostman.com/json/collection/v2.1.0/collection.json" + }, + "item": [ + { + "name": "GET Method", + "request": { + "method": "GET", + "header": [], + "url": { + "raw": "https://put-your-api-gateway-stage-address-here/v0/mock?method=created", + "protocol": "https", + "host": [ + "put-your-api-gateway-stage-address-here" + ], + "path": [ + "v0", + "mock" + ], + "query": [ + { + "key": "method", + "value": "created" + } + ] + } + }, + "response": [] + }, + { + "name": "POST Method", + "request": { + "method": "POST", + "header": [ + { + "key": "Content-Type", + "value": "application/json", + "type": "text" + } + ], + "body": { + "mode": "raw", + "raw": "{\r\n \"statusCode\": 226\r\n}" + }, + "url": { + "raw": "https://put-your-api-gateway-stage-address-here/v0/mock", + "protocol": "https", + "host": [ + "put-your-api-gateway-stage-address-here" + ], + "path": [ + "v0", + "mock" + ], + "query": [ + { + "key": "scope", + "value": "internal", + "disabled": true + } + ] + } + }, + "response": [] + } + ] +} \ No newline at end of file From aeec25aa69a402acaf60871d560156ca7aed923b Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Vin=C3=ADcius=20Pereira?= Date: Fri, 19 Nov 2021 20:02:20 -0300 Subject: [PATCH 3/3] created folder for the blog post --- .../AWS Blog Post.SVwithAPIGateway.postman_collection.json | 0 blog-assets/{ => svcvirt-apigateway-cfn}/template.yaml | 0 2 files changed, 0 insertions(+), 0 deletions(-) rename blog-assets/{ => svcvirt-apigateway-cfn}/AWS Blog Post.SVwithAPIGateway.postman_collection.json (100%) rename blog-assets/{ => svcvirt-apigateway-cfn}/template.yaml (100%) diff --git a/blog-assets/AWS Blog Post.SVwithAPIGateway.postman_collection.json b/blog-assets/svcvirt-apigateway-cfn/AWS Blog Post.SVwithAPIGateway.postman_collection.json similarity index 100% rename from blog-assets/AWS Blog Post.SVwithAPIGateway.postman_collection.json rename to blog-assets/svcvirt-apigateway-cfn/AWS Blog Post.SVwithAPIGateway.postman_collection.json diff --git a/blog-assets/template.yaml b/blog-assets/svcvirt-apigateway-cfn/template.yaml similarity index 100% rename from blog-assets/template.yaml rename to blog-assets/svcvirt-apigateway-cfn/template.yaml