Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
32 commits
Select commit Hold shift + click to select a range
6a8912e
Use fnGetAtt instead of ref
Jan 26, 2021
568666e
Return gracefully
Jan 26, 2021
f705e03
chore: update develop with latest release branch (#1822)
mndeveci Nov 20, 2020
5d0e645
feature: Support for Lambda Code Signing (#53) (#1825) (#1828)
mndeveci Nov 23, 2020
6c01c39
Release v1.31.0 (#1836)
mndeveci Nov 26, 2020
270f7c4
feat(images): additions to SAM spec (#1844)
sriram-mv Dec 1, 2020
febde6e
Support DLQ, RetryPolicy properties for EventBridgeRule,Schedule even…
ejafarli Dec 2, 2020
acde9bc
fix: propagate condition to sqs queue policy for sqssubscription (#1798)
hawflau Dec 2, 2020
48cf143
chore: Remove biased language from pylintrc (#1847)
aahung Dec 11, 2020
04c585c
feat: Stream Analytics (#1865)
mndeveci Dec 17, 2020
9f267a4
chore: version bump 1.33 (#1866)
mndeveci Dec 17, 2020
f6e370a
fix: Support new CodeDeploy ManagedPolicy (#1858)
jfuss Dec 29, 2020
fd840a3
fix: Update Slack invite link (#1877)
jfuss Dec 31, 2020
3e2edec
feature: Support for custom checkpointing (#1883)
vinayaksood Jan 7, 2021
5658413
Fix: Description in AWS::Serverless::HttpApi (#1884)
hawflau Jan 8, 2021
75230ba
Update AWS::S3::Bucket properties (#1885)
hawflau Jan 8, 2021
fe838d7
Fix: Replaced invalid AMQ managed policy by providing policy statemen…
qingchm Jan 14, 2021
a617205
chore: bump version 1.34.0 (#1892)
hawflau Jan 15, 2021
4112fcf
test: Add simple integration tests (#1797)
mingkun2020 Jan 18, 2021
2c77424
fix: Better Error Handling of Intrinsics (#1896)
awood45 Jan 25, 2021
4cdc265
Add integration test
Jan 29, 2021
9618694
Merge branch 'develop' into fix-function-alias
Jan 29, 2021
8c19a09
Add trailing newline
Jan 29, 2021
0848e38
Update comment
Jan 29, 2021
1a0c464
Add UT
Feb 1, 2021
08088b7
make black
Feb 1, 2021
ecb089c
Update comment
Feb 1, 2021
70b61e3
Add integ test for default alias
Feb 3, 2021
6ead5e4
Update tests
Feb 4, 2021
7d43bb1
Add TODO comment
Feb 5, 2021
364eaa6
Add E2E test
Feb 9, 2021
0e160ab
Function output in constant
Feb 9, 2021
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: 6 additions & 0 deletions integration/helpers/base_test.py
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,7 @@
class BaseTest(TestCase):
@classmethod
def setUpClass(cls):
cls.FUNCTION_OUTPUT = "hello"
cls.tests_integ_dir = Path(__file__).resolve().parents[1]
cls.resources_dir = Path(cls.tests_integ_dir, "resources")
cls.template_dir = Path(cls.resources_dir, "templates", "single")
Expand Down Expand Up @@ -216,6 +217,11 @@ def get_api_v2_stack_stages(self):

return self.client_provider.api_v2_client.get_stages(ApiId=resources[0]["PhysicalResourceId"])["Items"]

def get_api_v2_endpoint(self, logical_id):
api_id = self.get_physical_id_by_logical_id(logical_id)
api = self.client_provider.api_v2_client.get_api(ApiId=api_id)
return api["ApiEndpoint"]

def get_stack_nested_stack_resources(self):
resources = self.get_stack_resources("AWS::CloudFormation::Stack")

Expand Down
Binary file modified integration/resources/code/code.zip
Binary file not shown.
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
[
{ "LogicalResourceId":"MyLambdaFunction", "ResourceType":"AWS::Lambda::Function" },
{ "LogicalResourceId":"MyLambdaFunctionAliaslive", "ResourceType":"AWS::Lambda::Alias" },
{ "LogicalResourceId":"MyLambdaFunctionRole", "ResourceType":"AWS::IAM::Role" },
{ "LogicalResourceId":"MyLambdaFunctionVersion", "ResourceType":"AWS::Lambda::Version" },
{ "LogicalResourceId":"MyLambdaFunctionFooEventPermission", "ResourceType":"AWS::Lambda::Permission" },
{ "LogicalResourceId":"MyLambdaFunctionBarEventPermission", "ResourceType":"AWS::Lambda::Permission" },
{ "LogicalResourceId":"MyHttpApi", "ResourceType":"AWS::ApiGatewayV2::Api" },
{ "LogicalResourceId":"MyHttpApiApiGatewayDefaultStage", "ResourceType":"AWS::ApiGatewayV2::Stage" }
]
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
[
{ "LogicalResourceId":"MyLambdaFunction", "ResourceType":"AWS::Lambda::Function" },
{ "LogicalResourceId":"MyLambdaFunctionRole", "ResourceType":"AWS::IAM::Role" },
{ "LogicalResourceId":"MyLambdaFunctionFooEventPermission", "ResourceType":"AWS::Lambda::Permission" },
{ "LogicalResourceId":"MyHttpApi", "ResourceType":"AWS::ApiGatewayV2::Api" },
{ "LogicalResourceId":"MyHttpApiApiGatewayDefaultStage", "ResourceType":"AWS::ApiGatewayV2::Stage" }
]
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
Resources:
MyHttpApi:
Type: AWS::Serverless::HttpApi
MyLambdaFunction:
Type: AWS::Serverless::Function
Properties:
AutoPublishAlias: live
Handler: index.handler
Runtime: nodejs12.x
CodeUri: ${codeuri}
Events:
FooEvent:
Type: HttpApi
Properties:
ApiId:
Ref: MyHttpApi
BarEvent:
Type: HttpApi
Properties:
ApiId:
Ref: MyHttpApi
Path: /bar
Method: POST
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
Resources:
MyHttpApi:
Type: AWS::Serverless::HttpApi
MyLambdaFunction:
Type: AWS::Serverless::Function
Properties:
Handler: index.handler
Runtime: nodejs12.x
CodeUri: ${codeuri}
Events:
FooEvent:
Type: HttpApi
Properties:
ApiId:
Ref: MyHttpApi
BarEvent:
Type: HttpApi
Properties:
ApiId:
Ref: MyHttpApi
Path: /bar
Method: POST
14 changes: 14 additions & 0 deletions integration/single/test_basic_function.py
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
import requests
from parameterized import parameterized
from integration.helpers.base_test import BaseTest

Expand Down Expand Up @@ -26,6 +27,19 @@ def test_basic_function(self, file_name):

self.assertEqual(self.get_resource_status_by_logical_id("MyLambdaFunction"), "UPDATE_COMPLETE")

@parameterized.expand(
[
"function_with_http_api_events",
"function_alias_with_http_api_events",
]
)
def test_function_with_http_api_events(self, file_name):
self.create_and_verify_stack(file_name)

endpoint = self.get_api_v2_endpoint("MyHttpApi")

self.assertEqual(requests.get(endpoint).text, self.FUNCTION_OUTPUT)

@parameterized.expand(
[
("basic_function_with_sns_dlq", "sns:Publish"),
Expand Down
9 changes: 8 additions & 1 deletion samtranslator/open_api/open_api.py
Original file line number Diff line number Diff line change
Expand Up @@ -102,7 +102,14 @@ def get_integration_function_logical_id(self, path_name, method_name):

# Extract lambda integration (${LambdaName.Arn}) and split ".Arn" off from it
regex = "([A-Za-z0-9]+\.Arn)"
match = re.findall(regex, arn)[0].split(".Arn")[0]
matches = re.findall(regex, arn)
# Prevent IndexError when integration URI doesn't contain .Arn (e.g. a Function with
# AutoPublishAlias translates to AWS::Lambda::Alias, which make_shorthand represents
# as LogicalId instead of LogicalId.Arn).
# TODO: Consistent handling of Functions with and without AutoPublishAlias (see #1901)
if not matches:
return False
match = matches[0].split(".Arn")[0]
return match

def method_has_integration(self, method):
Expand Down
47 changes: 47 additions & 0 deletions tests/openapi/test_openapi.py
Original file line number Diff line number Diff line change
Expand Up @@ -437,3 +437,50 @@ def test_must_not_add_description_if_already_defined(self):
editor = OpenApiEditor(self.original_openapi_with_description)
editor.add_description("New Description")
self.assertEqual(editor.openapi["info"]["description"], "Existing Description")


class TestOpenApiEditor_get_integration_function_of_alias(TestCase):
def setUp(self):

self.original_openapi = {
"openapi": "3.0.1",
"paths": {
"$default": {
"x-amazon-apigateway-any-method": {
"Fn::If": [
"condition",
{
"security": [{"OpenIdAuth": ["scope1", "scope2"]}],
"isDefaultRoute": True,
"x-amazon-apigateway-integration": {
"httpMethod": "POST",
"type": "aws_proxy",
"uri": {
"Fn::If": [
"condition",
{
"Fn::Sub": "arn:${AWS::Partition}:apigateway:${AWS::Region}:lambda:path/2015-03-31/functions/${HttpApiFunctionAlias}/invocations"
},
{"Ref": "AWS::NoValue"},
]
},
"payloadFormatVersion": "1.0",
},
"responses": {},
},
{"Ref": "AWS::NoValue"},
]
}
},
"/bar": {},
"/badpath": "string value",
},
}

self.editor = OpenApiEditor(self.original_openapi)

def test_no_logical_id_if_alias(self):

self.assertFalse(
self.editor.get_integration_function_logical_id(OpenApiEditor._DEFAULT_PATH, OpenApiEditor._X_ANY_METHOD),
)