Skip to content
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

Add location tests #2826

Merged
merged 6 commits into from
Jan 27, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
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
2 changes: 1 addition & 1 deletion integration/combination/test_connectors.py
Original file line number Diff line number Diff line change
Expand Up @@ -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",),
Expand All @@ -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,
Expand Down
Original file line number Diff line number Diff line change
@@ -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"
}
]
Original file line number Diff line number Diff line change
@@ -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
38 changes: 38 additions & 0 deletions tests/translator/input/connector_function_to_location.yaml
Original file line number Diff line number Diff line change
@@ -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
150 changes: 150 additions & 0 deletions tests/translator/output/aws-cn/connector_function_to_location.json
Original file line number Diff line number Diff line change
@@ -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"
}
}
}
Loading