From e0f4564df4122e14014347082d2fb6f3e094dee0 Mon Sep 17 00:00:00 2001 From: Gavin Zhang Date: Fri, 27 Jan 2023 12:04:01 -0800 Subject: [PATCH 1/3] Add transform and integ tests for location connector --- integration/combination/test_connectors.py | 2 +- ...ctor_function_to_location_place_index.json | 18 +++ ...ctor_function_to_location_place_index.yaml | 59 +++++++ .../input/connector_function_to_location.yaml | 38 +++++ .../connector_function_to_location.json | 150 ++++++++++++++++++ .../connector_function_to_location.json | 150 ++++++++++++++++++ .../connector_function_to_location.json | 150 ++++++++++++++++++ 7 files changed, 566 insertions(+), 1 deletion(-) create mode 100644 integration/resources/expected/combination/connector_function_to_location_place_index.json create mode 100644 integration/resources/templates/combination/connector_function_to_location_place_index.yaml create mode 100644 tests/translator/input/connector_function_to_location.yaml create mode 100644 tests/translator/output/aws-cn/connector_function_to_location.json create mode 100644 tests/translator/output/aws-us-gov/connector_function_to_location.json create mode 100644 tests/translator/output/connector_function_to_location.json 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..af3eaa019 --- /dev/null +++ b/integration/resources/templates/combination/connector_function_to_location_place_index.yaml @@ -0,0 +1,59 @@ +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 + ) + print(response) + response = client.search_place_index_for_position( + IndexName=indexName, + MaxResults=10, + Language='en', + Position=[ + -123.12, + 49.28 + ] + )['Results'][0] + print(response) + response = client.search_place_index_for_text( + IndexName=indexName, + Text="effiel tow" + ) + print(response) + response = client.search_place_index_for_suggestions( + IndexName=indexName, + Text="effiel tow" + ) + print(response) + 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 \ No newline at end of file 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..f42c62c9a --- /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 \ No newline at end of file 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..d19df15ac --- /dev/null +++ b/tests/translator/output/aws-cn/connector_function_to_location.json @@ -0,0 +1,150 @@ +{ + "Resources": { + "MyPlace": { + "Type": "AWS::Location::PlaceIndex", + "Properties": { + "DataSource": "Here", + "IndexName": "MyPlaceIndex" + } + }, + "MyFunction": { + "Type": "AWS::Lambda::Function", + "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" + } + ] + } + }, + "MyFunctionRole": { + "Type": "AWS::IAM::Role", + "Properties": { + "AssumeRolePolicyDocument": { + "Version": "2012-10-17", + "Statement": [ + { + "Action": [ + "sts:AssumeRole" + ], + "Effect": "Allow", + "Principal": { + "Service": [ + "lambda.amazonaws.com" + ] + } + } + ] + }, + "ManagedPolicyArns": [ + "arn:aws-cn:iam::aws:policy/service-role/AWSLambdaBasicExecutionRole" + ], + "Tags": [ + { + "Key": "lambda:createdBy", + "Value": "SAM" + } + ] + } + }, + "MyConnectorPolicy": { + "Type": "AWS::IAM::ManagedPolicy", + "Metadata": { + "aws:sam:connectors": { + "MyConnector": { + "Source": { + "Type": "AWS::Serverless::Function" + }, + "Destination": { + "Type": "AWS::Location::PlaceIndex" + } + } + } + }, + "Properties": { + "PolicyDocument": { + "Version": "2012-10-17", + "Statement": [ + { + "Effect": "Allow", + "Action": [ + "geo:DescribePlaceIndex", + "geo:GetPlace", + "geo:SearchPlaceIndexForPosition", + "geo:SearchPlaceIndexForSuggestions", + "geo:SearchPlaceIndexForText" + ], + "Resource": [ + { + "Fn::Sub": "arn:${AWS::Partition}:geo:us-east-1:123123123123:place-index/explore.place" + } + ] + } + ] + }, + "Roles": [ + { + "Ref": "MyFunctionRole" + } + ] + } + }, + "MyConnectorWithIdPolicy": { + "Type": "AWS::IAM::ManagedPolicy", + "Metadata": { + "aws:sam:connectors": { + "MyConnectorWithId": { + "Source": { + "Type": "AWS::Serverless::Function" + }, + "Destination": { + "Type": "AWS::Location::PlaceIndex" + } + } + } + }, + "Properties": { + "PolicyDocument": { + "Version": "2012-10-17", + "Statement": [ + { + "Effect": "Allow", + "Action": [ + "geo:DescribePlaceIndex", + "geo:GetPlace", + "geo:SearchPlaceIndexForPosition", + "geo:SearchPlaceIndexForSuggestions", + "geo:SearchPlaceIndexForText" + ], + "Resource": [ + { + "Fn::GetAtt": [ + "MyPlace", + "Arn" + ] + } + ] + } + ] + }, + "Roles": [ + { + "Ref": "MyFunctionRole" + } + ] + } + } + } +} \ No newline at end of file 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..cf71d79c4 --- /dev/null +++ b/tests/translator/output/aws-us-gov/connector_function_to_location.json @@ -0,0 +1,150 @@ +{ + "Resources": { + "MyPlace": { + "Type": "AWS::Location::PlaceIndex", + "Properties": { + "DataSource": "Here", + "IndexName": "MyPlaceIndex" + } + }, + "MyFunction": { + "Type": "AWS::Lambda::Function", + "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" + } + ] + } + }, + "MyFunctionRole": { + "Type": "AWS::IAM::Role", + "Properties": { + "AssumeRolePolicyDocument": { + "Version": "2012-10-17", + "Statement": [ + { + "Action": [ + "sts:AssumeRole" + ], + "Effect": "Allow", + "Principal": { + "Service": [ + "lambda.amazonaws.com" + ] + } + } + ] + }, + "ManagedPolicyArns": [ + "arn:aws-us-gov:iam::aws:policy/service-role/AWSLambdaBasicExecutionRole" + ], + "Tags": [ + { + "Key": "lambda:createdBy", + "Value": "SAM" + } + ] + } + }, + "MyConnectorPolicy": { + "Type": "AWS::IAM::ManagedPolicy", + "Metadata": { + "aws:sam:connectors": { + "MyConnector": { + "Source": { + "Type": "AWS::Serverless::Function" + }, + "Destination": { + "Type": "AWS::Location::PlaceIndex" + } + } + } + }, + "Properties": { + "PolicyDocument": { + "Version": "2012-10-17", + "Statement": [ + { + "Effect": "Allow", + "Action": [ + "geo:DescribePlaceIndex", + "geo:GetPlace", + "geo:SearchPlaceIndexForPosition", + "geo:SearchPlaceIndexForSuggestions", + "geo:SearchPlaceIndexForText" + ], + "Resource": [ + { + "Fn::Sub": "arn:${AWS::Partition}:geo:us-east-1:123123123123:place-index/explore.place" + } + ] + } + ] + }, + "Roles": [ + { + "Ref": "MyFunctionRole" + } + ] + } + }, + "MyConnectorWithIdPolicy": { + "Type": "AWS::IAM::ManagedPolicy", + "Metadata": { + "aws:sam:connectors": { + "MyConnectorWithId": { + "Source": { + "Type": "AWS::Serverless::Function" + }, + "Destination": { + "Type": "AWS::Location::PlaceIndex" + } + } + } + }, + "Properties": { + "PolicyDocument": { + "Version": "2012-10-17", + "Statement": [ + { + "Effect": "Allow", + "Action": [ + "geo:DescribePlaceIndex", + "geo:GetPlace", + "geo:SearchPlaceIndexForPosition", + "geo:SearchPlaceIndexForSuggestions", + "geo:SearchPlaceIndexForText" + ], + "Resource": [ + { + "Fn::GetAtt": [ + "MyPlace", + "Arn" + ] + } + ] + } + ] + }, + "Roles": [ + { + "Ref": "MyFunctionRole" + } + ] + } + } + } +} \ No newline at end of file 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..91232a256 --- /dev/null +++ b/tests/translator/output/connector_function_to_location.json @@ -0,0 +1,150 @@ +{ + "Resources": { + "MyPlace": { + "Type": "AWS::Location::PlaceIndex", + "Properties": { + "DataSource": "Here", + "IndexName": "MyPlaceIndex" + } + }, + "MyFunction": { + "Type": "AWS::Lambda::Function", + "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" + } + ] + } + }, + "MyFunctionRole": { + "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": [ + { + "Key": "lambda:createdBy", + "Value": "SAM" + } + ] + } + }, + "MyConnectorPolicy": { + "Type": "AWS::IAM::ManagedPolicy", + "Metadata": { + "aws:sam:connectors": { + "MyConnector": { + "Source": { + "Type": "AWS::Serverless::Function" + }, + "Destination": { + "Type": "AWS::Location::PlaceIndex" + } + } + } + }, + "Properties": { + "PolicyDocument": { + "Version": "2012-10-17", + "Statement": [ + { + "Effect": "Allow", + "Action": [ + "geo:DescribePlaceIndex", + "geo:GetPlace", + "geo:SearchPlaceIndexForPosition", + "geo:SearchPlaceIndexForSuggestions", + "geo:SearchPlaceIndexForText" + ], + "Resource": [ + { + "Fn::Sub": "arn:${AWS::Partition}:geo:us-east-1:123123123123:place-index/explore.place" + } + ] + } + ] + }, + "Roles": [ + { + "Ref": "MyFunctionRole" + } + ] + } + }, + "MyConnectorWithIdPolicy": { + "Type": "AWS::IAM::ManagedPolicy", + "Metadata": { + "aws:sam:connectors": { + "MyConnectorWithId": { + "Source": { + "Type": "AWS::Serverless::Function" + }, + "Destination": { + "Type": "AWS::Location::PlaceIndex" + } + } + } + }, + "Properties": { + "PolicyDocument": { + "Version": "2012-10-17", + "Statement": [ + { + "Effect": "Allow", + "Action": [ + "geo:DescribePlaceIndex", + "geo:GetPlace", + "geo:SearchPlaceIndexForPosition", + "geo:SearchPlaceIndexForSuggestions", + "geo:SearchPlaceIndexForText" + ], + "Resource": [ + { + "Fn::GetAtt": [ + "MyPlace", + "Arn" + ] + } + ] + } + ] + }, + "Roles": [ + { + "Ref": "MyFunctionRole" + } + ] + } + } + } +} \ No newline at end of file From d0adbd61ac36b102f7f2c69668ef204bca39ad65 Mon Sep 17 00:00:00 2001 From: Gavin Zhang Date: Fri, 27 Jan 2023 12:07:01 -0800 Subject: [PATCH 2/3] Format file --- ...ctor_function_to_location_place_index.yaml | 6 +- .../input/connector_function_to_location.yaml | 2 +- .../connector_function_to_location.json | 152 +++++----- .../connector_function_to_location.json | 152 +++++----- .../connector_function_to_location.json | 280 +++++++++--------- 5 files changed, 297 insertions(+), 295 deletions(-) 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 index af3eaa019..be76ffd4c 100644 --- a/integration/resources/templates/combination/connector_function_to_location_place_index.yaml +++ b/integration/resources/templates/combination/connector_function_to_location_place_index.yaml @@ -40,7 +40,7 @@ Resources: Environment: Variables: LOCATION_INDEX: !Sub ${AWS::StackName}-PlaceIndex - + MyPlace: Type: AWS::Location::PlaceIndex @@ -56,4 +56,6 @@ Resources: Destination: Id: MyPlace Permissions: - - Read \ No newline at end of file + - Read +Metadata: + SamTransformTest: true diff --git a/tests/translator/input/connector_function_to_location.yaml b/tests/translator/input/connector_function_to_location.yaml index f42c62c9a..6256e6a58 100644 --- a/tests/translator/input/connector_function_to_location.yaml +++ b/tests/translator/input/connector_function_to_location.yaml @@ -35,4 +35,4 @@ Resources: Destination: Id: MyPlace Permissions: - - Read \ No newline at end of file + - 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 index d19df15ac..1131d55c4 100644 --- a/tests/translator/output/aws-cn/connector_function_to_location.json +++ b/tests/translator/output/aws-cn/connector_function_to_location.json @@ -1,84 +1,22 @@ { "Resources": { - "MyPlace": { - "Type": "AWS::Location::PlaceIndex", - "Properties": { - "DataSource": "Here", - "IndexName": "MyPlaceIndex" - } - }, - "MyFunction": { - "Type": "AWS::Lambda::Function", - "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" - } - ] - } - }, - "MyFunctionRole": { - "Type": "AWS::IAM::Role", - "Properties": { - "AssumeRolePolicyDocument": { - "Version": "2012-10-17", - "Statement": [ - { - "Action": [ - "sts:AssumeRole" - ], - "Effect": "Allow", - "Principal": { - "Service": [ - "lambda.amazonaws.com" - ] - } - } - ] - }, - "ManagedPolicyArns": [ - "arn:aws-cn:iam::aws:policy/service-role/AWSLambdaBasicExecutionRole" - ], - "Tags": [ - { - "Key": "lambda:createdBy", - "Value": "SAM" - } - ] - } - }, "MyConnectorPolicy": { - "Type": "AWS::IAM::ManagedPolicy", "Metadata": { "aws:sam:connectors": { "MyConnector": { - "Source": { - "Type": "AWS::Serverless::Function" - }, "Destination": { "Type": "AWS::Location::PlaceIndex" + }, + "Source": { + "Type": "AWS::Serverless::Function" } } } }, "Properties": { "PolicyDocument": { - "Version": "2012-10-17", "Statement": [ { - "Effect": "Allow", "Action": [ "geo:DescribePlaceIndex", "geo:GetPlace", @@ -86,41 +24,41 @@ "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": { - "Type": "AWS::IAM::ManagedPolicy", "Metadata": { "aws:sam:connectors": { "MyConnectorWithId": { - "Source": { - "Type": "AWS::Serverless::Function" - }, "Destination": { "Type": "AWS::Location::PlaceIndex" + }, + "Source": { + "Type": "AWS::Serverless::Function" } } } }, "Properties": { "PolicyDocument": { - "Version": "2012-10-17", "Statement": [ { - "Effect": "Allow", "Action": [ "geo:DescribePlaceIndex", "geo:GetPlace", @@ -128,6 +66,7 @@ "geo:SearchPlaceIndexForSuggestions", "geo:SearchPlaceIndexForText" ], + "Effect": "Allow", "Resource": [ { "Fn::GetAtt": [ @@ -137,14 +76,75 @@ } ] } - ] + ], + "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" } } -} \ No newline at end of file +} 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 index cf71d79c4..0c62dc82f 100644 --- a/tests/translator/output/aws-us-gov/connector_function_to_location.json +++ b/tests/translator/output/aws-us-gov/connector_function_to_location.json @@ -1,84 +1,22 @@ { "Resources": { - "MyPlace": { - "Type": "AWS::Location::PlaceIndex", - "Properties": { - "DataSource": "Here", - "IndexName": "MyPlaceIndex" - } - }, - "MyFunction": { - "Type": "AWS::Lambda::Function", - "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" - } - ] - } - }, - "MyFunctionRole": { - "Type": "AWS::IAM::Role", - "Properties": { - "AssumeRolePolicyDocument": { - "Version": "2012-10-17", - "Statement": [ - { - "Action": [ - "sts:AssumeRole" - ], - "Effect": "Allow", - "Principal": { - "Service": [ - "lambda.amazonaws.com" - ] - } - } - ] - }, - "ManagedPolicyArns": [ - "arn:aws-us-gov:iam::aws:policy/service-role/AWSLambdaBasicExecutionRole" - ], - "Tags": [ - { - "Key": "lambda:createdBy", - "Value": "SAM" - } - ] - } - }, "MyConnectorPolicy": { - "Type": "AWS::IAM::ManagedPolicy", "Metadata": { "aws:sam:connectors": { "MyConnector": { - "Source": { - "Type": "AWS::Serverless::Function" - }, "Destination": { "Type": "AWS::Location::PlaceIndex" + }, + "Source": { + "Type": "AWS::Serverless::Function" } } } }, "Properties": { "PolicyDocument": { - "Version": "2012-10-17", "Statement": [ { - "Effect": "Allow", "Action": [ "geo:DescribePlaceIndex", "geo:GetPlace", @@ -86,41 +24,41 @@ "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": { - "Type": "AWS::IAM::ManagedPolicy", "Metadata": { "aws:sam:connectors": { "MyConnectorWithId": { - "Source": { - "Type": "AWS::Serverless::Function" - }, "Destination": { "Type": "AWS::Location::PlaceIndex" + }, + "Source": { + "Type": "AWS::Serverless::Function" } } } }, "Properties": { "PolicyDocument": { - "Version": "2012-10-17", "Statement": [ { - "Effect": "Allow", "Action": [ "geo:DescribePlaceIndex", "geo:GetPlace", @@ -128,6 +66,7 @@ "geo:SearchPlaceIndexForSuggestions", "geo:SearchPlaceIndexForText" ], + "Effect": "Allow", "Resource": [ { "Fn::GetAtt": [ @@ -137,14 +76,75 @@ } ] } - ] + ], + "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" } } -} \ No newline at end of file +} diff --git a/tests/translator/output/connector_function_to_location.json b/tests/translator/output/connector_function_to_location.json index 91232a256..36b646c83 100644 --- a/tests/translator/output/connector_function_to_location.json +++ b/tests/translator/output/connector_function_to_location.json @@ -1,150 +1,150 @@ { - "Resources": { - "MyPlace": { - "Type": "AWS::Location::PlaceIndex", - "Properties": { - "DataSource": "Here", - "IndexName": "MyPlaceIndex" - } - }, - "MyFunction": { - "Type": "AWS::Lambda::Function", - "Properties": { - "Code": { - "ZipFile": "const AWS = require('aws-sdk');\nexports.handler = async (event) => {\n console.log(JSON.stringify(event));\n};\n" + "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" }, - "Handler": "index.handler", - "Role": { - "Fn::GetAtt": [ - "MyFunctionRole", - "Arn" - ] + "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" }, - "Runtime": "nodejs14.x", - "Tags": [ - { - "Key": "lambda:createdBy", - "Value": "SAM" - } - ] - } - }, - "MyFunctionRole": { - "Type": "AWS::IAM::Role", - "Properties": { - "AssumeRolePolicyDocument": { - "Version": "2012-10-17", - "Statement": [ - { - "Action": [ - "sts:AssumeRole" - ], - "Effect": "Allow", - "Principal": { - "Service": [ - "lambda.amazonaws.com" + "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" }, - "ManagedPolicyArns": [ - "arn:aws:iam::aws:policy/service-role/AWSLambdaBasicExecutionRole" - ], - "Tags": [ - { - "Key": "lambda:createdBy", - "Value": "SAM" - } - ] - } - }, - "MyConnectorPolicy": { - "Type": "AWS::IAM::ManagedPolicy", - "Metadata": { - "aws:sam:connectors": { - "MyConnector": { - "Source": { - "Type": "AWS::Serverless::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" + } + ] }, - "Destination": { - "Type": "AWS::Location::PlaceIndex" - } - } - } - }, - "Properties": { - "PolicyDocument": { - "Version": "2012-10-17", - "Statement": [ - { - "Effect": "Allow", - "Action": [ - "geo:DescribePlaceIndex", - "geo:GetPlace", - "geo:SearchPlaceIndexForPosition", - "geo:SearchPlaceIndexForSuggestions", - "geo:SearchPlaceIndexForText" - ], - "Resource": [ - { - "Fn::Sub": "arn:${AWS::Partition}:geo:us-east-1:123123123123:place-index/explore.place" - } - ] - } - ] + "Type": "AWS::IAM::Role" }, - "Roles": [ - { - "Ref": "MyFunctionRole" - } - ] - } - }, - "MyConnectorWithIdPolicy": { - "Type": "AWS::IAM::ManagedPolicy", - "Metadata": { - "aws:sam:connectors": { - "MyConnectorWithId": { - "Source": { - "Type": "AWS::Serverless::Function" + "MyPlace": { + "Properties": { + "DataSource": "Here", + "IndexName": "MyPlaceIndex" }, - "Destination": { - "Type": "AWS::Location::PlaceIndex" - } - } + "Type": "AWS::Location::PlaceIndex" } - }, - "Properties": { - "PolicyDocument": { - "Version": "2012-10-17", - "Statement": [ - { - "Effect": "Allow", - "Action": [ - "geo:DescribePlaceIndex", - "geo:GetPlace", - "geo:SearchPlaceIndexForPosition", - "geo:SearchPlaceIndexForSuggestions", - "geo:SearchPlaceIndexForText" - ], - "Resource": [ - { - "Fn::GetAtt": [ - "MyPlace", - "Arn" - ] - } - ] - } - ] - }, - "Roles": [ - { - "Ref": "MyFunctionRole" - } - ] - } } - } -} \ No newline at end of file +} From 463dcc2358de9cd897739a5fcb1f4cbd0bc1ff94 Mon Sep 17 00:00:00 2001 From: Gavin Zhang Date: Fri, 27 Jan 2023 13:22:06 -0800 Subject: [PATCH 3/3] Format file --- .../connector_function_to_location_place_index.yaml | 6 +----- 1 file changed, 1 insertion(+), 5 deletions(-) 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 index be76ffd4c..241bfb569 100644 --- a/integration/resources/templates/combination/connector_function_to_location_place_index.yaml +++ b/integration/resources/templates/combination/connector_function_to_location_place_index.yaml @@ -16,7 +16,6 @@ Resources: response = client.describe_place_index( IndexName=indexName ) - print(response) response = client.search_place_index_for_position( IndexName=indexName, MaxResults=10, @@ -25,18 +24,15 @@ Resources: -123.12, 49.28 ] - )['Results'][0] - print(response) + ) response = client.search_place_index_for_text( IndexName=indexName, Text="effiel tow" ) - print(response) response = client.search_place_index_for_suggestions( IndexName=indexName, Text="effiel tow" ) - print(response) Environment: Variables: LOCATION_INDEX: !Sub ${AWS::StackName}-PlaceIndex