Skip to content

(feat) CloudFormation AWS::ApiGateway::RestApi support #1238

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
Merged
Show file tree
Hide file tree
Changes from 4 commits
Commits
Show all changes
30 commits
Select commit Hold shift + click to select a range
8f6b8fb
Initial setup and work
viksrivat Jun 17, 2019
f457401
Add RestApi tests
viksrivat Jun 19, 2019
8112cf4
Remove Stage Name/Variable from pr
viksrivat Jun 20, 2019
5050dd8
Run make pr
viksrivat Jun 20, 2019
bf5a083
Add Rest Api integration test
viksrivat Jun 20, 2019
6eb226a
Remove AWS::Stage from current pr
viksrivat Jun 20, 2019
7c5823d
Update integration test to only use CloudFormation types
viksrivat Jun 20, 2019
4966513
Re-run Travis Ci
viksrivat Jun 24, 2019
2c38ede
Update Uri to BodyS3Location
viksrivat Jun 24, 2019
9d3d137
Add docstring to extract_swagger_api
viksrivat Jun 24, 2019
b6d9b62
Fix Merge conflicts with dev and branch
viksrivat Jun 24, 2019
54bda7f
Test local file in body fail and clean tests
viksrivat Jun 24, 2019
9b06696
Initial Attempt
viksrivat Jun 25, 2019
145162e
Refactor Sam API provider
viksrivat Jun 25, 2019
5615163
Cleanup Refactoring
viksrivat Jun 25, 2019
752fba8
Merge pull request #1 from viksrivat/feature/cloud_formation_api_prov…
viksrivat Jun 25, 2019
681ede3
Re-run travis
viksrivat Jun 25, 2019
997845c
Initial Refactor refactor
viksrivat Jun 26, 2019
de65fd0
Fix tests and run make pr
viksrivat Jun 26, 2019
4555f11
Reorganize classes
viksrivat Jun 27, 2019
420a842
Update docstrings
viksrivat Jun 27, 2019
6803a0b
Restructure to seperate SAM and CF providers seperately + tests
viksrivat Jun 27, 2019
837137f
Remove transform flag in the rest-api
viksrivat Jun 27, 2019
4130ea2
Remove BaseProvider object
viksrivat Jun 27, 2019
19eaebe
Update tests and code with comments
viksrivat Jun 27, 2019
23467de
Update tests with comments
viksrivat Jun 28, 2019
066b236
Trigger
viksrivat Jun 28, 2019
8987db2
Remove noapievent
viksrivat Jun 28, 2019
4a792bf
Update tests
viksrivat Jun 28, 2019
7662f24
Fixed comments
viksrivat Jul 8, 2019
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 3 additions & 3 deletions tests/integration/local/start_api/start_api_integ_base.py
Original file line number Diff line number Diff line change
Expand Up @@ -33,9 +33,9 @@ def setUpClass(cls):

@classmethod
def start_api(cls):
command = "sam"
if os.getenv("SAM_CLI_DEV"):
command = "samdev"
# command = "sam"
# if os.getenv("SAM_CLI_DEV"):
command = "samdev"

cls.start_api_process = Popen([command, "local", "start-api", "-t", cls.template, "-p", cls.port, "--debug"])
# we need to wait some time for start-api to start, hence the sleep
Expand Down
6 changes: 0 additions & 6 deletions tests/integration/local/start_api/test_start_api.py
Original file line number Diff line number Diff line change
Expand Up @@ -362,12 +362,6 @@ def test_function_not_defined_in_template(self):
self.assertEquals(response.status_code, 502)
self.assertEquals(response.json(), {"message": "No function defined for resource method"})

def test_function_with_no_api_event_is_reachable(self):
response = requests.get(self.url + "/functionwithnoapievent")

self.assertEquals(response.status_code, 200)
self.assertEquals(response.json(), {'hello': 'world'})

def test_lambda_function_resource_is_reachable(self):
response = requests.get(self.url + "/nonserverlessfunction")

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ AWSTemplateFormatVersion: '2010-09-09'
Resources:
Base64ResponseFunction:
Properties:
CodeUri: "."
Code: "."
Handler: main.base64_response
Runtime: python3.6
Type: AWS::Lambda::Function
Expand All @@ -27,7 +27,7 @@ Resources:
responses: {}
type: aws_proxy
uri:
Fn::Sub: arn:aws:apigateway:${AWS::Region}:lambda:path/2015-03-31/functions/${MyLambdaFunction.Arn}/invocations
Fn::Sub: arn:aws:apigateway:${AWS::Region}:lambda:path/2015-03-31/functions/${MyNonServerlessLambdaFunction.Arn}/invocations
"/base64response":
get:
x-amazon-apigateway-integration:
Expand All @@ -42,14 +42,6 @@ Resources:
type: aws_proxy
uri:
Fn::Sub: arn:aws:apigateway:${AWS::Region}:lambda:path/2015-03-31/functions/${EchoBase64EventBodyFunction.Arn}/invocations
"/functionwithnoapievent":
get:
x-amazon-apigateway-integration:
httpMethod: POST
responses: {}
type: aws_proxy
uri:
Fn::Sub: arn:aws:apigateway:${AWS::Region}:lambda:path/2015-03-31/functions/${NoApiEventFunction.Arn}/invocations
"/nofunctionfound":
get:
x-amazon-apigateway-integration:
Expand All @@ -69,29 +61,9 @@ Resources:
- image/gif
StageName: prod
Type: AWS::ApiGateway::RestApi
MyLambdaFunction:
Properties:
CodeUri: "."
Events:
GetApi:
Properties:
Method: GET
Path: "/get"
RestApiId:
Ref: MyApi
Type: Api
Handler: main.handler
Runtime: python3.6
Type: AWS::Lambda::Function
MyNonServerlessLambdaFunction:
Properties:
CodeUri: "."
Handler: main.handler
Runtime: python3.6
Type: AWS::Lambda::Function
NoApiEventFunction:
Properties:
CodeUri: "."
Code: "."
Handler: main.handler
Runtime: python3.6
Type: AWS::Lambda::Function
35 changes: 34 additions & 1 deletion tests/unit/commands/local/lib/test_api_provider.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,9 @@

from mock import patch

from samcli.commands.local.lib.api_provider import ApiProvider, SamApiProvider, CfnApiProvider
from samcli.commands.local.lib.api_provider import ApiProvider
from samcli.commands.local.lib.sam_api_provider import SamApiProvider
from samcli.commands.local.lib.cfn_api_provider import CfnApiProvider


class TestApiProvider_init(TestCase):
Expand All @@ -25,6 +27,37 @@ def test_provider_with_valid_template(self, SamBaseProviderMock, extract_api_moc


class TestApiProviderSelection(TestCase):
def test_default_provider(self):
resources = {
"TestApi": {
"Type": "AWS::UNKNOWN_TYPE",
"Properties": {
"StageName": "dev",
"DefinitionBody": {
"paths": {
"/path": {
"get": {
"x-amazon-apigateway-integration": {
"httpMethod": "POST",
"type": "aws_proxy",
"uri": {
"Fn::Sub": "arn:aws:apigateway:${AWS::Region}:lambda:path/2015-03-31"
"/functions/${NoApiEventFunction.Arn}/invocations",
},
"responses": {},
},
}
}

}
}
}
}
}

provider = ApiProvider.find_api_provider(resources)
self.assertTrue(isinstance(provider, SamApiProvider))

def test_api_provider_sam_api(self):
resources = {
"TestApi": {
Expand Down
4 changes: 2 additions & 2 deletions tests/unit/commands/local/lib/test_cfn_api_provider.py
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@
from tests.unit.commands.local.lib.test_sam_api_provider import make_swagger


class TestSamApiProviderwithApiGatewayRestApi(TestCase):
class TestApiProviderWithApiGatewayRestApi(TestCase):

def setUp(self):
self.binary_types = ["image/png", "image/jpg"]
Expand Down Expand Up @@ -102,7 +102,7 @@ def test_body_with_swagger_as_local_file_expect_fail(self):
self.assertRaises(Exception, ApiProvider, template)

@patch("samcli.commands.local.lib.cfn_base_api_provider.SamSwaggerReader")
def test_with_swagger_as_both_body_and_uri(self, SamSwaggerReaderMock):
def test_with_swagger_as_both_body_and_uri_called(self, SamSwaggerReaderMock):
body = {"some": "body"}
filename = "somefile.txt"

Expand Down
2 changes: 1 addition & 1 deletion tests/unit/commands/local/lib/test_sam_api_provider.py
Original file line number Diff line number Diff line change
Expand Up @@ -475,7 +475,7 @@ def test_with_swagger_as_local_file(self):
assertCountEqual(self, self.input_apis, provider.apis)

@patch("samcli.commands.local.lib.cfn_base_api_provider.SamSwaggerReader")
def test_with_swagger_as_both_body_and_uri(self, SamSwaggerReaderMock):
def test_with_swagger_as_both_body_and_uri_called(self, SamSwaggerReaderMock):
body = {"some": "body"}
filename = "somefile.txt"

Expand Down