Skip to content

Commit 0062d28

Browse files
committed
NRCan Geolocation Mock API. Switch to self-hosted Nominatim. Other fixes to schemas in bucket-content
1 parent 9d0b91f commit 0062d28

File tree

9 files changed

+367
-27
lines changed

9 files changed

+367
-27
lines changed

docs/cloudformation/geolocator-web-presence.yml

Lines changed: 243 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -106,7 +106,37 @@ Resources:
106106
Path: /*
107107
Method: any
108108
Layers:
109-
- arn:aws:lambda:ca-central-1:759472643633:layer:opensearchpy-layer:2
109+
- !Sub "arn:aws:lambda:ca-central-1:${AWS::AccountId}:layer:opensearchpy-layer:3"
110+
- arn:aws:lambda:ca-central-1:336392948345:layer:AWSSDKPandas-Python313:3
111+
112+
NRCanGeoLocationLambda:
113+
Type: AWS::Serverless::Function
114+
Properties:
115+
Runtime: python3.13
116+
Role: !GetAtt LambdaExecutionRole.Arn
117+
CodeUri:
118+
Bucket: !Ref DeploymentBucket
119+
Key: cloudformation-templates/lambda/geolocator/nrcan-geolocation-api-20251208-1200.zip
120+
MemorySize: 3009
121+
Handler: lambda_function.lambda_handler
122+
Timeout: 30
123+
Environment:
124+
Variables:
125+
ADDRESS_RANGE_INDEX: geolocation-index-address-range
126+
ANALYTICS_TABLE_NAME: geolocation-analytics-table
127+
INDEX_NAME: geolocation-index
128+
MY_AWS_REGION: ca-central-1
129+
OS_ENDPOINT: !Ref OSEndpoint
130+
OS_SECRET_ID: !Ref OSSecretID
131+
Events:
132+
ApiEvent:
133+
Type: Api
134+
Properties:
135+
RestApiId: !Ref RestApi
136+
Path: /*
137+
Method: any
138+
Layers:
139+
- !Sub "arn:aws:lambda:ca-central-1:${AWS::AccountId}:layer:opensearchpy-layer:3"
110140
- arn:aws:lambda:ca-central-1:336392948345:layer:AWSSDKPandas-Python313:3
111141

112142
LambdaExecutionRole:
@@ -144,7 +174,7 @@ Resources:
144174
- Effect: Allow
145175
Action:
146176
- secretsmanager:GetSecretValue
147-
Resource: !Sub "arn:aws:secretsmanager:ca-central-1:${AWS::AccountId}:secret:OpenSearchSecret-geocore-semantic-search-with-opensearch-stage*"
177+
Resource: !Sub "arn:aws:secretsmanager:ca-central-1:${AWS::AccountId}:secret:OpenSearchSecret-geocore-semantic-search-with-opensearch-${Environment}*"
148178
- Effect: Allow
149179
Action:
150180
- es:ESHttpGet
@@ -386,6 +416,217 @@ Resources:
386416
"user_agent": "$context.identity.userAgent",
387417
"http_method": "$context.httpMethod"
388418
}
419+
/geolocation/en/locate:
420+
get:
421+
consumes:
422+
- "application/json"
423+
produces:
424+
- "application/json"
425+
responses: #Method response:https://docs.aws.amazon.com/AWSCloudFormation/latest/UserGuide/aws-properties-apigateway-method-methodresponse.html
426+
"200":
427+
description: "200 response"
428+
# schema:
429+
# $ref: "#/definitions/Empty"
430+
headers:
431+
Access-Control-Allow-Origin:
432+
type: "string"
433+
x-amazon-apigateway-integration: #Integration response:https://docs.aws.amazon.com/serverless-application-model/latest/developerguide/sam-specification-api-gateway-extensions.html
434+
type: aws
435+
httpMethod: POST
436+
uri: !Sub 'arn:aws:apigateway:${AWS::Region}:lambda:path/2015-03-31/functions/${NRCanGeoLocationLambda.Arn}/invocations'
437+
responses:
438+
default:
439+
statusCode: "200"
440+
responseParameters:
441+
method.response.header.Access-Control-Allow-Origin: "'*'"
442+
requestTemplates:
443+
application/json: |
444+
{
445+
"q": "$input.params('q')",
446+
"bbox": "$input.params('bbox')",
447+
"referrer": "$input.params('referrer')",
448+
"ip_address": "$context.identity.sourceIp",
449+
"timestamp": "$context.requestTimeEpoch",
450+
"user_agent": "$context.identity.userAgent",
451+
"http_method": "$context.httpMethod",
452+
"path": "$context.path"
453+
}
454+
/geolocation/en/autocomplete:
455+
get:
456+
consumes:
457+
- "application/json"
458+
produces:
459+
- "application/json"
460+
responses: #Method response:https://docs.aws.amazon.com/AWSCloudFormation/latest/UserGuide/aws-properties-apigateway-method-methodresponse.html
461+
"200":
462+
description: "200 response"
463+
# schema:
464+
# $ref: "#/definitions/Empty"
465+
headers:
466+
Access-Control-Allow-Origin:
467+
type: "string"
468+
x-amazon-apigateway-integration: #Integration response:https://docs.aws.amazon.com/serverless-application-model/latest/developerguide/sam-specification-api-gateway-extensions.html
469+
type: aws
470+
httpMethod: POST
471+
uri: !Sub 'arn:aws:apigateway:${AWS::Region}:lambda:path/2015-03-31/functions/${NRCanGeoLocationLambda.Arn}/invocations'
472+
responses:
473+
default:
474+
statusCode: "200"
475+
responseParameters:
476+
method.response.header.Access-Control-Allow-Origin: "'*'"
477+
requestTemplates:
478+
application/json: |
479+
{
480+
"q": "$input.params('q')",
481+
"bbox": "$input.params('bbox')",
482+
"referrer": "$input.params('referrer')",
483+
"ip_address": "$context.identity.sourceIp",
484+
"timestamp": "$context.requestTimeEpoch",
485+
"user_agent": "$context.identity.userAgent",
486+
"http_method": "$context.httpMethod",
487+
"path": "$context.path"
488+
}
489+
/geolocation/en/suggest:
490+
get:
491+
consumes:
492+
- "application/json"
493+
produces:
494+
- "application/json"
495+
responses: #Method response:https://docs.aws.amazon.com/AWSCloudFormation/latest/UserGuide/aws-properties-apigateway-method-methodresponse.html
496+
"200":
497+
description: "200 response"
498+
# schema:
499+
# $ref: "#/definitions/Empty"
500+
headers:
501+
Access-Control-Allow-Origin:
502+
type: "string"
503+
x-amazon-apigateway-integration: #Integration response:https://docs.aws.amazon.com/serverless-application-model/latest/developerguide/sam-specification-api-gateway-extensions.html
504+
type: aws
505+
httpMethod: POST
506+
uri: !Sub 'arn:aws:apigateway:${AWS::Region}:lambda:path/2015-03-31/functions/${NRCanGeoLocationLambda.Arn}/invocations'
507+
responses:
508+
default:
509+
statusCode: "200"
510+
responseParameters:
511+
method.response.header.Access-Control-Allow-Origin: "'*'"
512+
requestTemplates:
513+
application/json: |
514+
{
515+
"q": "$input.params('q')",
516+
"bbox": "$input.params('bbox')",
517+
"referrer": "$input.params('referrer')",
518+
"ip_address": "$context.identity.sourceIp",
519+
"timestamp": "$context.requestTimeEpoch",
520+
"user_agent": "$context.identity.userAgent",
521+
"http_method": "$context.httpMethod",
522+
"path": "$context.path"
523+
}
524+
/geolocation/fr/locate:
525+
get:
526+
consumes:
527+
- "application/json"
528+
produces:
529+
- "application/json"
530+
responses: #Method response:https://docs.aws.amazon.com/AWSCloudFormation/latest/UserGuide/aws-properties-apigateway-method-methodresponse.html
531+
"200":
532+
description: "200 response"
533+
# schema:
534+
# $ref: "#/definitions/Empty"
535+
headers:
536+
Access-Control-Allow-Origin:
537+
type: "string"
538+
x-amazon-apigateway-integration: #Integration response:https://docs.aws.amazon.com/serverless-application-model/latest/developerguide/sam-specification-api-gateway-extensions.html
539+
type: aws
540+
httpMethod: POST
541+
uri: !Sub 'arn:aws:apigateway:${AWS::Region}:lambda:path/2015-03-31/functions/${NRCanGeoLocationLambda.Arn}/invocations'
542+
responses:
543+
default:
544+
statusCode: "200"
545+
responseParameters:
546+
method.response.header.Access-Control-Allow-Origin: "'*'"
547+
requestTemplates:
548+
application/json: |
549+
{
550+
"q": "$input.params('q')",
551+
"bbox": "$input.params('bbox')",
552+
"referrer": "$input.params('referrer')",
553+
"ip_address": "$context.identity.sourceIp",
554+
"timestamp": "$context.requestTimeEpoch",
555+
"user_agent": "$context.identity.userAgent",
556+
"http_method": "$context.httpMethod",
557+
"path": "$context.path"
558+
}
559+
/geolocation/fr/autocomplete:
560+
get:
561+
consumes:
562+
- "application/json"
563+
produces:
564+
- "application/json"
565+
responses: #Method response:https://docs.aws.amazon.com/AWSCloudFormation/latest/UserGuide/aws-properties-apigateway-method-methodresponse.html
566+
"200":
567+
description: "200 response"
568+
# schema:
569+
# $ref: "#/definitions/Empty"
570+
headers:
571+
Access-Control-Allow-Origin:
572+
type: "string"
573+
x-amazon-apigateway-integration: #Integration response:https://docs.aws.amazon.com/serverless-application-model/latest/developerguide/sam-specification-api-gateway-extensions.html
574+
type: aws
575+
httpMethod: POST
576+
uri: !Sub 'arn:aws:apigateway:${AWS::Region}:lambda:path/2015-03-31/functions/${NRCanGeoLocationLambda.Arn}/invocations'
577+
responses:
578+
default:
579+
statusCode: "200"
580+
responseParameters:
581+
method.response.header.Access-Control-Allow-Origin: "'*'"
582+
requestTemplates:
583+
application/json: |
584+
{
585+
"q": "$input.params('q')",
586+
"bbox": "$input.params('bbox')",
587+
"referrer": "$input.params('referrer')",
588+
"ip_address": "$context.identity.sourceIp",
589+
"timestamp": "$context.requestTimeEpoch",
590+
"user_agent": "$context.identity.userAgent",
591+
"http_method": "$context.httpMethod",
592+
"path": "$context.path"
593+
}
594+
/geolocation/fr/suggest:
595+
get:
596+
consumes:
597+
- "application/json"
598+
produces:
599+
- "application/json"
600+
responses: #Method response:https://docs.aws.amazon.com/AWSCloudFormation/latest/UserGuide/aws-properties-apigateway-method-methodresponse.html
601+
"200":
602+
description: "200 response"
603+
# schema:
604+
# $ref: "#/definitions/Empty"
605+
headers:
606+
Access-Control-Allow-Origin:
607+
type: "string"
608+
x-amazon-apigateway-integration: #Integration response:https://docs.aws.amazon.com/serverless-application-model/latest/developerguide/sam-specification-api-gateway-extensions.html
609+
type: aws
610+
httpMethod: POST
611+
uri: !Sub 'arn:aws:apigateway:${AWS::Region}:lambda:path/2015-03-31/functions/${NRCanGeoLocationLambda.Arn}/invocations'
612+
responses:
613+
default:
614+
statusCode: "200"
615+
responseParameters:
616+
method.response.header.Access-Control-Allow-Origin: "'*'"
617+
requestTemplates:
618+
application/json: |
619+
{
620+
"q": "$input.params('q')",
621+
"bbox": "$input.params('bbox')",
622+
"referrer": "$input.params('referrer')",
623+
"ip_address": "$context.identity.sourceIp",
624+
"timestamp": "$context.requestTimeEpoch",
625+
"user_agent": "$context.identity.userAgent",
626+
"http_method": "$context.httpMethod",
627+
"path": "$context.path"
628+
}
629+
389630
geolocatorS3Bucket:
390631
Type: AWS::S3::Bucket
391632
Properties:

docs/lambda/geolocator/geolocator-bucket-content/api/in-api-schema.json

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,6 @@
44
"type": "object",
55
"version": 1.0,
66
"comments": "Schema for GeoView-API-geolocator input-query. The items inside parameters properties are the parameters provided by the URL.",
7-
87
"properties": {
98
"params": {
109
"type": "object",
@@ -23,7 +22,7 @@
2322
"type": "string",
2423
"enum": ["en", "fr"],
2524
"default" : "en",
26-
"description": "The language on wich to filter the query."
25+
"description": "The language on which to filter the query."
2726
},
2827
"dev": {
2928
"type": "string",
@@ -42,7 +41,7 @@
4241
"uniqueItems": true,
4342
"items": {
4443
"type": "string",
45-
"enum": ["geonames", "nominatim", "locate"]
44+
"enum": ["geonames", "nominatim", "locate", "fsa", "nts"]
4645
},
4746
"description": "The list of supported API key to query. Optional parameter, if missing, all supported key will be query."
4847
}

docs/lambda/geolocator/geolocator-bucket-content/api/out-api-schema.json

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -106,7 +106,13 @@
106106
"type": "array",
107107
"uniqueItems": true,
108108
"items": { "$ref": "#/definitions/output" },
109-
"description": "The ens api result set."
109+
"description": "The nts api result set."
110+
},
111+
"fsa": {
112+
"type": "array",
113+
"uniqueItems": true,
114+
"items": { "$ref": "#/definitions/output" },
115+
"description": "The fsa api result set."
110116
}
111117
},
112118
"description": "List of supported key for the API. As we add key, we need to had an entry in the schema. The entry MUST be the same key as the in in-api-schema.json (keys enum parameter)."
Lines changed: 47 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,47 @@
1+
{
2+
"url": "https://geolocator.api.geo.ca/fsa",
3+
"urlParams": {},
4+
"staticParams": {},
5+
"urlCodeTables": {},
6+
"lookup": {
7+
"in": {
8+
"q": "q",
9+
"lang": "accept-language"
10+
},
11+
"out": {
12+
"structure": {
13+
"type": "list"
14+
},
15+
"data": {
16+
"name": {
17+
"field": "name",
18+
"lookup": ""
19+
},
20+
"province": {
21+
"field": "province",
22+
"lookup": ""
23+
},
24+
"category": {
25+
"field": "category",
26+
"lookup": ""
27+
},
28+
"lat": {
29+
"field": "lat",
30+
"lookup": ""
31+
},
32+
"lng": {
33+
"field": "long",
34+
"lookup": ""
35+
},
36+
"bbox": {
37+
"field": "bbox",
38+
"lookup": ""
39+
},
40+
"tag": {
41+
"field": "tag",
42+
"lookup": ""
43+
}
44+
}
45+
}
46+
}
47+
}

docs/lambda/geolocator/geolocator-bucket-content/services/locate-schema.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
{
2-
"url": "https://geogratis.gc.ca/services/geolocation/_PARAM1_/locate",
2+
"url": "https://geolocator.api.geo.ca/geolocation/_PARAM1_/locate",
33
"urlParams": {
44
"param1": "lang"
55
},

docs/lambda/geolocator/geolocator-bucket-content/services/nominatim-schema.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
{
2-
"url": "https://nominatim.openstreetmap.org/search",
2+
"url": "https://maps.canada.ca/nominatim/search",
33
"urlParams": {},
44
"staticParams": {
55
"countrycodes": "CA",

0 commit comments

Comments
 (0)