-
Notifications
You must be signed in to change notification settings - Fork 2.4k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat: Add support for the
FailOnWarnings
property on `AWS::Serverle…
…ss::Api` (#2417) * initial logic for supporting the FailOnWarnings property * initial unit tests added * initial pass at integration test logic * parameterised FailOnWarnings value in api_with_fail_on_warnings.yaml * api_with_fail_on_warnings test added to tests/translator/test_translator.py * reverted change in tests/translator/test_translator.py
- Loading branch information
Showing
13 changed files
with
537 additions
and
1 deletion.
There are no files selected for viewing
This file contains 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 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 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 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 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 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 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 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 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 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.