forked from kunal-bham/access911
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathsetup_geocoding.py
More file actions
executable file
·101 lines (85 loc) · 2.74 KB
/
setup_geocoding.py
File metadata and controls
executable file
·101 lines (85 loc) · 2.74 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
#!/usr/bin/env python3
"""
Setup AWS Location Service for Geocoding
Creates a Place Index for converting location text to coordinates
"""
import boto3
import os
from dotenv import load_dotenv
load_dotenv()
REGION = os.getenv("AWS_REGION", "us-east-1")
INDEX_NAME = "elevenlabs-place-index"
print("="*80)
print("🌍 SETTING UP AWS LOCATION SERVICE")
print("="*80)
location_client = boto3.client('location', region_name=REGION)
# Step 1: Create Place Index
print(f"\n📍 Creating Place Index: {INDEX_NAME}")
print("-" * 80)
try:
response = location_client.create_place_index(
IndexName=INDEX_NAME,
DataSource='Esri', # Options: Esri, Here
Description='Place index for geocoding emergency locations',
PricingPlan='RequestBasedUsage'
)
print(f"✅ Place Index created successfully!")
print(f" Index Name: {INDEX_NAME}")
print(f" ARN: {response['IndexArn']}")
print(f" Data Source: Esri")
except location_client.exceptions.ConflictException:
print(f"⚠️ Place Index '{INDEX_NAME}' already exists!")
# Get existing index details
response = location_client.describe_place_index(IndexName=INDEX_NAME)
print(f" Index Name: {response['IndexName']}")
print(f" ARN: {response['IndexArn']}")
print(f" Data Source: {response['DataSource']}")
except Exception as e:
print(f"❌ Failed to create Place Index: {e}")
exit(1)
# Step 2: Test geocoding
print(f"\n🧪 Testing geocoding...")
print("-" * 80)
test_locations = [
"San Francisco, CA",
"Nashville, Tennessee",
"123 Main Street, New York, NY"
]
for location in test_locations:
try:
result = location_client.search_place_index_for_text(
IndexName=INDEX_NAME,
Text=location,
MaxResults=1
)
if result['Results']:
coords = result['Results'][0]['Place']['Geometry']['Point']
label = result['Results'][0]['Place']['Label']
print(f"✅ '{location}'")
print(f" → {label}")
print(f" → Lat: {coords[1]:.6f}, Lon: {coords[0]:.6f}")
else:
print(f"⚠️ No results for '{location}'")
except Exception as e:
print(f"❌ Error geocoding '{location}': {e}")
print("\n" + "="*80)
print("✅ AWS LOCATION SERVICE SETUP COMPLETE!")
print("="*80)
print(f"\n📝 Add this to your Lambda environment variables:")
print(f" LOCATION_INDEX={INDEX_NAME}")
print(f"\n📝 Update Lambda IAM role to include these permissions:")
print("""
{
"Version": "2012-10-17",
"Statement": [
{
"Effect": "Allow",
"Action": [
"geo:SearchPlaceIndexForText"
],
"Resource": "arn:aws:geo:us-east-1:*:place-index/elevenlabs-place-index"
}
]
}
""")
print("="*80)