-
Notifications
You must be signed in to change notification settings - Fork 2.4k
feat: Add support for the FailOnWarnings
property on AWS::Serverless::Api
#2417
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
Changes from all commits
Commits
Show all changes
7 commits
Select commit
Hold shift + click to select a range
92b25fb
initial logic for supporting the FailOnWarnings property
nialdaly ec1dcd0
initial unit tests added
nialdaly 9256a6a
Merge branch develop into feature/fail-on-warnings
nialdaly 0643633
initial pass at integration test logic
nialdaly 5553d97
parameterised FailOnWarnings value in api_with_fail_on_warnings.yaml
nialdaly 69006d3
api_with_fail_on_warnings test added to tests/translator/test_transla…
nialdaly 3e88c04
reverted change in tests/translator/test_translator.py
nialdaly File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,29 @@ | ||
from parameterized import parameterized | ||
|
||
from integration.helpers.base_test import BaseTest | ||
|
||
|
||
class TestApiWithFailOnWarnings(BaseTest): | ||
@parameterized.expand( | ||
[ | ||
("combination/api_with_fail_on_warnings", True), | ||
("combination/api_with_fail_on_warnings", False), | ||
] | ||
) | ||
def test_end_point_configuration(self, file_name, disable_value): | ||
parameters = [ | ||
{ | ||
"ParameterKey": "FailOnWarningsValue", | ||
"ParameterValue": "true" if disable_value else "false", | ||
"UsePreviousValue": False, | ||
"ResolvedValue": "string", | ||
} | ||
] | ||
|
||
self.create_and_verify_stack(file_name, parameters) | ||
|
||
rest_api_id = self.get_physical_id_by_type("AWS::ApiGateway::RestApi") | ||
apigw_client = self.client_provider.api_client | ||
|
||
api_result = apigw_client.get_rest_api(restApiId=rest_api_id) | ||
self.assertEqual(api_result["ResponseMetadata"]["HTTPStatusCode"], 200) |
8 changes: 8 additions & 0 deletions
8
integration/resources/expected/combination/api_with_fail_on_warnings.json
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,8 @@ | ||
[ | ||
{"LogicalResourceId": "RestApiGateway", "ResourceType": "AWS::ApiGateway::RestApi"}, | ||
{"LogicalResourceId": "RestApiGatewayDeployment", "ResourceType": "AWS::ApiGateway::Deployment"}, | ||
{"LogicalResourceId": "RestApiGatewayProdStage", "ResourceType": "AWS::ApiGateway::Stage"}, | ||
{"LogicalResourceId": "RestApiFunction", "ResourceType": "AWS::Lambda::Function"}, | ||
{"LogicalResourceId": "RestApiFunctionIamPermissionProd", "ResourceType": "AWS::Lambda::Permission"}, | ||
{"LogicalResourceId": "RestApiFunctionRole", "ResourceType": "AWS::IAM::Role"} | ||
] |
34 changes: 34 additions & 0 deletions
34
integration/resources/templates/combination/api_with_fail_on_warnings.yaml
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,34 @@ | ||
Parameters: | ||
FailOnWarningsValue: | ||
Type: String | ||
AllowedValues: [true, false] | ||
|
||
Resources: | ||
RestApiGateway: | ||
Type: AWS::Serverless::Api | ||
Properties: | ||
StageName: Prod | ||
FailOnWarnings: | ||
Ref: FailOnWarningsValue | ||
|
||
RestApiFunction: | ||
Type: AWS::Serverless::Function | ||
Properties: | ||
InlineCode: | | ||
exports.handler = async (event) => { | ||
const response = { | ||
statusCode: 200, | ||
body: JSON.stringify('Hello from Lambda!'), | ||
}; | ||
return response; | ||
}; | ||
Handler: index.handler | ||
Runtime: nodejs12.x | ||
Events: | ||
Iam: | ||
Type: Api | ||
Properties: | ||
RestApiId: | ||
Ref: RestApiGateway | ||
Method: GET | ||
Path: / |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,22 @@ | ||
Resources: | ||
ApiGatewayApi: | ||
Type: AWS::Serverless::Api | ||
Properties: | ||
StageName: prod | ||
FailOnWarnings: true | ||
ApiFunction: # Adds a GET api endpoint at "/" to the ApiGatewayApi via an Api event | ||
Type: AWS::Serverless::Function | ||
Properties: | ||
Events: | ||
ApiEvent: | ||
Type: Api | ||
Properties: | ||
Path: / | ||
Method: get | ||
RestApiId: | ||
Ref: ApiGatewayApi | ||
Runtime: python3.7 | ||
Handler: index.handler | ||
InlineCode: | | ||
def handler(event, context): | ||
return {'body': 'Hello World!', 'statusCode': 200} |
22 changes: 22 additions & 0 deletions
22
tests/translator/input/error_api_invalid_fail_on_warnings.yaml
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,22 @@ | ||
Resources: | ||
ApiGatewayApi: | ||
Type: AWS::Serverless::Api | ||
Properties: | ||
StageName: prod | ||
FailOnWarnings: '' | ||
ApiFunction: # Adds a GET api endpoint at "/" to the ApiGatewayApi via an Api event | ||
Type: AWS::Serverless::Function | ||
Properties: | ||
Events: | ||
ApiEvent: | ||
Type: Api | ||
Properties: | ||
Path: / | ||
Method: get | ||
RestApiId: | ||
Ref: ApiGatewayApi | ||
Runtime: python3.7 | ||
Handler: index.handler | ||
InlineCode: | | ||
def handler(event, context): | ||
return {'body': 'Hello World!', 'statusCode': 200} |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,128 @@ | ||
{ | ||
"Resources": { | ||
"ApiGatewayApi": { | ||
"Type": "AWS::ApiGateway::RestApi", | ||
"Properties": { | ||
"Body": { | ||
"info": { | ||
"version": "1.0", | ||
"title": { | ||
"Ref": "AWS::StackName" | ||
} | ||
}, | ||
"paths": { | ||
"/": { | ||
"get": { | ||
"x-amazon-apigateway-integration": { | ||
"httpMethod": "POST", | ||
"type": "aws_proxy", | ||
"uri": { | ||
"Fn::Sub": "arn:aws:apigateway:${AWS::Region}:lambda:path/2015-03-31/functions/${ApiFunction.Arn}/invocations" | ||
} | ||
}, | ||
"responses": {} | ||
} | ||
} | ||
}, | ||
"swagger": "2.0" | ||
}, | ||
"FailOnWarnings": true | ||
} | ||
}, | ||
"ApiGatewayApiDeploymentf96bc9abda": { | ||
"Type": "AWS::ApiGateway::Deployment", | ||
"Properties": { | ||
"RestApiId": { | ||
"Ref": "ApiGatewayApi" | ||
}, | ||
"Description": "RestApi deployment id: f96bc9abdad53c001153ce8ba04f1667c7b0a004", | ||
"StageName": "Stage" | ||
} | ||
}, | ||
"ApiFunctionRole": { | ||
"Type": "AWS::IAM::Role", | ||
"Properties": { | ||
"AssumeRolePolicyDocument": { | ||
"Version": "2012-10-17", | ||
"Statement": [ | ||
{ | ||
"Action": [ | ||
"sts:AssumeRole" | ||
], | ||
"Effect": "Allow", | ||
"Principal": { | ||
"Service": [ | ||
"lambda.amazonaws.com" | ||
] | ||
} | ||
} | ||
] | ||
}, | ||
"ManagedPolicyArns": [ | ||
"arn:aws:iam::aws:policy/service-role/AWSLambdaBasicExecutionRole" | ||
], | ||
"Tags": [ | ||
{ | ||
"Value": "SAM", | ||
"Key": "lambda:createdBy" | ||
} | ||
] | ||
} | ||
}, | ||
"ApiFunction": { | ||
"Type": "AWS::Lambda::Function", | ||
"Properties": { | ||
"Handler": "index.handler", | ||
"Code": { | ||
"ZipFile": "def handler(event, context):\n return {'body': 'Hello World!', 'statusCode': 200}\n" | ||
}, | ||
"Role": { | ||
"Fn::GetAtt": [ | ||
"ApiFunctionRole", | ||
"Arn" | ||
] | ||
}, | ||
"Runtime": "python3.7", | ||
"Tags": [ | ||
{ | ||
"Value": "SAM", | ||
"Key": "lambda:createdBy" | ||
} | ||
] | ||
} | ||
}, | ||
"ApiFunctionApiEventPermissionprod": { | ||
"Type": "AWS::Lambda::Permission", | ||
"Properties": { | ||
"Action": "lambda:InvokeFunction", | ||
"Principal": "apigateway.amazonaws.com", | ||
"FunctionName": { | ||
"Ref": "ApiFunction" | ||
}, | ||
"SourceArn": { | ||
"Fn::Sub": [ | ||
"arn:aws:execute-api:${AWS::Region}:${AWS::AccountId}:${__ApiId__}/${__Stage__}/GET/", | ||
{ | ||
"__Stage__": "*", | ||
"__ApiId__": { | ||
"Ref": "ApiGatewayApi" | ||
} | ||
} | ||
] | ||
} | ||
} | ||
}, | ||
"ApiGatewayApiprodStage": { | ||
"Type": "AWS::ApiGateway::Stage", | ||
"Properties": { | ||
"DeploymentId": { | ||
"Ref": "ApiGatewayApiDeploymentf96bc9abda" | ||
}, | ||
"RestApiId": { | ||
"Ref": "ApiGatewayApi" | ||
}, | ||
"StageName": "prod" | ||
} | ||
} | ||
} | ||
} |
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.