diff --git a/integration/combination/test_connectors.py b/integration/combination/test_connectors.py index 07189f705..47bc42a4a 100644 --- a/integration/combination/test_connectors.py +++ b/integration/combination/test_connectors.py @@ -46,6 +46,7 @@ def tearDown(self): ("combination/connector_event_rule_to_eb_custom_write",), ("combination/connector_event_rule_to_lambda_write",), ("combination/connector_event_rule_to_lambda_write_multiple",), + ("combination/connector_function_to_location_place_index",), ("combination/connector_mix_destination",), ("combination/connector_sqs_to_function",), ("combination/connector_sns_to_function_write",), @@ -60,7 +61,6 @@ def test_connector_by_invoking_a_function(self, template_file_path): lambda_function_name = self.get_physical_id_by_logical_id("TriggerFunction") lambda_client = self.client_provider.lambda_client - s3_client = self.client_provider.s3_client request_params = { "FunctionName": lambda_function_name, diff --git a/integration/resources/expected/combination/connector_function_to_location_place_index.json b/integration/resources/expected/combination/connector_function_to_location_place_index.json new file mode 100644 index 000000000..c0126116d --- /dev/null +++ b/integration/resources/expected/combination/connector_function_to_location_place_index.json @@ -0,0 +1,18 @@ +[ + { + "LogicalResourceId": "TriggerFunctionRole", + "ResourceType": "AWS::IAM::Role" + }, + { + "LogicalResourceId": "TriggerFunction", + "ResourceType": "AWS::Lambda::Function" + }, + { + "LogicalResourceId": "MyPlace", + "ResourceType": "AWS::Location::PlaceIndex" + }, + { + "LogicalResourceId": "MyConnectorPolicy", + "ResourceType": "AWS::IAM::ManagedPolicy" + } +] diff --git a/integration/resources/templates/combination/connector_function_to_location_place_index.yaml b/integration/resources/templates/combination/connector_function_to_location_place_index.yaml new file mode 100644 index 000000000..241bfb569 --- /dev/null +++ b/integration/resources/templates/combination/connector_function_to_location_place_index.yaml @@ -0,0 +1,57 @@ +Transform: AWS::Serverless-2016-10-31-test + +Resources: + TriggerFunction: + Type: AWS::Serverless::Function + Properties: + Runtime: python3.8 + Handler: index.handler + InlineCode: | + import boto3 + import os + client = boto3.client('location') + + def handler(event, context): + indexName = os.environ['LOCATION_INDEX'] + response = client.describe_place_index( + IndexName=indexName + ) + response = client.search_place_index_for_position( + IndexName=indexName, + MaxResults=10, + Language='en', + Position=[ + -123.12, + 49.28 + ] + ) + response = client.search_place_index_for_text( + IndexName=indexName, + Text="effiel tow" + ) + response = client.search_place_index_for_suggestions( + IndexName=indexName, + Text="effiel tow" + ) + Environment: + Variables: + LOCATION_INDEX: !Sub ${AWS::StackName}-PlaceIndex + + + MyPlace: + Type: AWS::Location::PlaceIndex + Properties: + DataSource: Here + IndexName: !Sub ${AWS::StackName}-PlaceIndex + + MyConnector: + Type: AWS::Serverless::Connector + Properties: + Source: + Id: TriggerFunction + Destination: + Id: MyPlace + Permissions: + - Read +Metadata: + SamTransformTest: true diff --git a/tests/translator/input/connector_function_to_location.yaml b/tests/translator/input/connector_function_to_location.yaml new file mode 100644 index 000000000..6256e6a58 --- /dev/null +++ b/tests/translator/input/connector_function_to_location.yaml @@ -0,0 +1,38 @@ +Resources: + MyFunction: + Type: AWS::Serverless::Function + Properties: + Runtime: nodejs14.x + Handler: index.handler + InlineCode: | + const AWS = require('aws-sdk'); + exports.handler = async (event) => { + console.log(JSON.stringify(event)); + }; + + MyPlace: + Type: AWS::Location::PlaceIndex + Properties: + DataSource: Here + IndexName: MyPlaceIndex + + MyConnector: + Type: AWS::Serverless::Connector + Properties: + Source: + Id: MyFunction + Destination: + Arn: !Sub arn:${AWS::Partition}:geo:us-east-1:123123123123:place-index/explore.place + Type: AWS::Location::PlaceIndex + Permissions: + - Read + + MyConnectorWithId: + Type: AWS::Serverless::Connector + Properties: + Source: + Id: MyFunction + Destination: + Id: MyPlace + Permissions: + - Read diff --git a/tests/translator/output/aws-cn/connector_function_to_location.json b/tests/translator/output/aws-cn/connector_function_to_location.json new file mode 100644 index 000000000..1131d55c4 --- /dev/null +++ b/tests/translator/output/aws-cn/connector_function_to_location.json @@ -0,0 +1,150 @@ +{ + "Resources": { + "MyConnectorPolicy": { + "Metadata": { + "aws:sam:connectors": { + "MyConnector": { + "Destination": { + "Type": "AWS::Location::PlaceIndex" + }, + "Source": { + "Type": "AWS::Serverless::Function" + } + } + } + }, + "Properties": { + "PolicyDocument": { + "Statement": [ + { + "Action": [ + "geo:DescribePlaceIndex", + "geo:GetPlace", + "geo:SearchPlaceIndexForPosition", + "geo:SearchPlaceIndexForSuggestions", + "geo:SearchPlaceIndexForText" + ], + "Effect": "Allow", + "Resource": [ + { + "Fn::Sub": "arn:${AWS::Partition}:geo:us-east-1:123123123123:place-index/explore.place" + } + ] + } + ], + "Version": "2012-10-17" + }, + "Roles": [ + { + "Ref": "MyFunctionRole" + } + ] + }, + "Type": "AWS::IAM::ManagedPolicy" + }, + "MyConnectorWithIdPolicy": { + "Metadata": { + "aws:sam:connectors": { + "MyConnectorWithId": { + "Destination": { + "Type": "AWS::Location::PlaceIndex" + }, + "Source": { + "Type": "AWS::Serverless::Function" + } + } + } + }, + "Properties": { + "PolicyDocument": { + "Statement": [ + { + "Action": [ + "geo:DescribePlaceIndex", + "geo:GetPlace", + "geo:SearchPlaceIndexForPosition", + "geo:SearchPlaceIndexForSuggestions", + "geo:SearchPlaceIndexForText" + ], + "Effect": "Allow", + "Resource": [ + { + "Fn::GetAtt": [ + "MyPlace", + "Arn" + ] + } + ] + } + ], + "Version": "2012-10-17" + }, + "Roles": [ + { + "Ref": "MyFunctionRole" + } + ] + }, + "Type": "AWS::IAM::ManagedPolicy" + }, + "MyFunction": { + "Properties": { + "Code": { + "ZipFile": "const AWS = require('aws-sdk');\nexports.handler = async (event) => {\n console.log(JSON.stringify(event));\n};\n" + }, + "Handler": "index.handler", + "Role": { + "Fn::GetAtt": [ + "MyFunctionRole", + "Arn" + ] + }, + "Runtime": "nodejs14.x", + "Tags": [ + { + "Key": "lambda:createdBy", + "Value": "SAM" + } + ] + }, + "Type": "AWS::Lambda::Function" + }, + "MyFunctionRole": { + "Properties": { + "AssumeRolePolicyDocument": { + "Statement": [ + { + "Action": [ + "sts:AssumeRole" + ], + "Effect": "Allow", + "Principal": { + "Service": [ + "lambda.amazonaws.com" + ] + } + } + ], + "Version": "2012-10-17" + }, + "ManagedPolicyArns": [ + "arn:aws-cn:iam::aws:policy/service-role/AWSLambdaBasicExecutionRole" + ], + "Tags": [ + { + "Key": "lambda:createdBy", + "Value": "SAM" + } + ] + }, + "Type": "AWS::IAM::Role" + }, + "MyPlace": { + "Properties": { + "DataSource": "Here", + "IndexName": "MyPlaceIndex" + }, + "Type": "AWS::Location::PlaceIndex" + } + } +} diff --git a/tests/translator/output/aws-us-gov/connector_function_to_location.json b/tests/translator/output/aws-us-gov/connector_function_to_location.json new file mode 100644 index 000000000..0c62dc82f --- /dev/null +++ b/tests/translator/output/aws-us-gov/connector_function_to_location.json @@ -0,0 +1,150 @@ +{ + "Resources": { + "MyConnectorPolicy": { + "Metadata": { + "aws:sam:connectors": { + "MyConnector": { + "Destination": { + "Type": "AWS::Location::PlaceIndex" + }, + "Source": { + "Type": "AWS::Serverless::Function" + } + } + } + }, + "Properties": { + "PolicyDocument": { + "Statement": [ + { + "Action": [ + "geo:DescribePlaceIndex", + "geo:GetPlace", + "geo:SearchPlaceIndexForPosition", + "geo:SearchPlaceIndexForSuggestions", + "geo:SearchPlaceIndexForText" + ], + "Effect": "Allow", + "Resource": [ + { + "Fn::Sub": "arn:${AWS::Partition}:geo:us-east-1:123123123123:place-index/explore.place" + } + ] + } + ], + "Version": "2012-10-17" + }, + "Roles": [ + { + "Ref": "MyFunctionRole" + } + ] + }, + "Type": "AWS::IAM::ManagedPolicy" + }, + "MyConnectorWithIdPolicy": { + "Metadata": { + "aws:sam:connectors": { + "MyConnectorWithId": { + "Destination": { + "Type": "AWS::Location::PlaceIndex" + }, + "Source": { + "Type": "AWS::Serverless::Function" + } + } + } + }, + "Properties": { + "PolicyDocument": { + "Statement": [ + { + "Action": [ + "geo:DescribePlaceIndex", + "geo:GetPlace", + "geo:SearchPlaceIndexForPosition", + "geo:SearchPlaceIndexForSuggestions", + "geo:SearchPlaceIndexForText" + ], + "Effect": "Allow", + "Resource": [ + { + "Fn::GetAtt": [ + "MyPlace", + "Arn" + ] + } + ] + } + ], + "Version": "2012-10-17" + }, + "Roles": [ + { + "Ref": "MyFunctionRole" + } + ] + }, + "Type": "AWS::IAM::ManagedPolicy" + }, + "MyFunction": { + "Properties": { + "Code": { + "ZipFile": "const AWS = require('aws-sdk');\nexports.handler = async (event) => {\n console.log(JSON.stringify(event));\n};\n" + }, + "Handler": "index.handler", + "Role": { + "Fn::GetAtt": [ + "MyFunctionRole", + "Arn" + ] + }, + "Runtime": "nodejs14.x", + "Tags": [ + { + "Key": "lambda:createdBy", + "Value": "SAM" + } + ] + }, + "Type": "AWS::Lambda::Function" + }, + "MyFunctionRole": { + "Properties": { + "AssumeRolePolicyDocument": { + "Statement": [ + { + "Action": [ + "sts:AssumeRole" + ], + "Effect": "Allow", + "Principal": { + "Service": [ + "lambda.amazonaws.com" + ] + } + } + ], + "Version": "2012-10-17" + }, + "ManagedPolicyArns": [ + "arn:aws-us-gov:iam::aws:policy/service-role/AWSLambdaBasicExecutionRole" + ], + "Tags": [ + { + "Key": "lambda:createdBy", + "Value": "SAM" + } + ] + }, + "Type": "AWS::IAM::Role" + }, + "MyPlace": { + "Properties": { + "DataSource": "Here", + "IndexName": "MyPlaceIndex" + }, + "Type": "AWS::Location::PlaceIndex" + } + } +} diff --git a/tests/translator/output/connector_function_to_location.json b/tests/translator/output/connector_function_to_location.json new file mode 100644 index 000000000..36b646c83 --- /dev/null +++ b/tests/translator/output/connector_function_to_location.json @@ -0,0 +1,150 @@ +{ + "Resources": { + "MyConnectorPolicy": { + "Metadata": { + "aws:sam:connectors": { + "MyConnector": { + "Destination": { + "Type": "AWS::Location::PlaceIndex" + }, + "Source": { + "Type": "AWS::Serverless::Function" + } + } + } + }, + "Properties": { + "PolicyDocument": { + "Statement": [ + { + "Action": [ + "geo:DescribePlaceIndex", + "geo:GetPlace", + "geo:SearchPlaceIndexForPosition", + "geo:SearchPlaceIndexForSuggestions", + "geo:SearchPlaceIndexForText" + ], + "Effect": "Allow", + "Resource": [ + { + "Fn::Sub": "arn:${AWS::Partition}:geo:us-east-1:123123123123:place-index/explore.place" + } + ] + } + ], + "Version": "2012-10-17" + }, + "Roles": [ + { + "Ref": "MyFunctionRole" + } + ] + }, + "Type": "AWS::IAM::ManagedPolicy" + }, + "MyConnectorWithIdPolicy": { + "Metadata": { + "aws:sam:connectors": { + "MyConnectorWithId": { + "Destination": { + "Type": "AWS::Location::PlaceIndex" + }, + "Source": { + "Type": "AWS::Serverless::Function" + } + } + } + }, + "Properties": { + "PolicyDocument": { + "Statement": [ + { + "Action": [ + "geo:DescribePlaceIndex", + "geo:GetPlace", + "geo:SearchPlaceIndexForPosition", + "geo:SearchPlaceIndexForSuggestions", + "geo:SearchPlaceIndexForText" + ], + "Effect": "Allow", + "Resource": [ + { + "Fn::GetAtt": [ + "MyPlace", + "Arn" + ] + } + ] + } + ], + "Version": "2012-10-17" + }, + "Roles": [ + { + "Ref": "MyFunctionRole" + } + ] + }, + "Type": "AWS::IAM::ManagedPolicy" + }, + "MyFunction": { + "Properties": { + "Code": { + "ZipFile": "const AWS = require('aws-sdk');\nexports.handler = async (event) => {\n console.log(JSON.stringify(event));\n};\n" + }, + "Handler": "index.handler", + "Role": { + "Fn::GetAtt": [ + "MyFunctionRole", + "Arn" + ] + }, + "Runtime": "nodejs14.x", + "Tags": [ + { + "Key": "lambda:createdBy", + "Value": "SAM" + } + ] + }, + "Type": "AWS::Lambda::Function" + }, + "MyFunctionRole": { + "Properties": { + "AssumeRolePolicyDocument": { + "Statement": [ + { + "Action": [ + "sts:AssumeRole" + ], + "Effect": "Allow", + "Principal": { + "Service": [ + "lambda.amazonaws.com" + ] + } + } + ], + "Version": "2012-10-17" + }, + "ManagedPolicyArns": [ + "arn:aws:iam::aws:policy/service-role/AWSLambdaBasicExecutionRole" + ], + "Tags": [ + { + "Key": "lambda:createdBy", + "Value": "SAM" + } + ] + }, + "Type": "AWS::IAM::Role" + }, + "MyPlace": { + "Properties": { + "DataSource": "Here", + "IndexName": "MyPlaceIndex" + }, + "Type": "AWS::Location::PlaceIndex" + } + } +}