AWS CDK Location Service (Alpha)

2.250.0a0 · active · verified Fri Apr 17

The AWS CDK Location Service Alpha module provides L2 (Level 2) constructs for interacting with AWS Location Service. This allows developers to define Location Service resources like Trackers, Geofence Collections, Maps, and Place Indexes using Python. As an 'alpha' module, its APIs are subject to change and it's generally not recommended for production use. It is released in lockstep with the main `aws-cdk-lib` package.

Common errors

Warnings

Install

Imports

Quickstart

This example demonstrates how to define a basic AWS CDK Stack that provisions an AWS Location Service Tracker and a Geofence Collection using the `aws-cdk-aws-location-alpha` module. Ensure `CDK_DEFAULT_ACCOUNT` and `CDK_DEFAULT_REGION` environment variables are set or explicitly provided for deployment.

import os
from aws_cdk import (
    Stack,
    App,
    Environment,
)
import aws_cdk.aws_location_alpha as location
from constructs import Construct

class MyLocationStack(Stack):
    def __init__(self, scope: Construct, construct_id: str, **kwargs) -> None:
        super().__init__(scope, construct_id, **kwargs)

        # Create an AWS Location Tracker
        tracker = location.Tracker(
            self, "MySimpleTracker",
            tracker_name="MyExampleTracker",
            description="A simple tracker for demonstration"
        )

        # Optional: Create a Geofence Collection
        geofence_collection = location.GeofenceCollection(
            self, "MySimpleGeofenceCollection",
            geofence_collection_name="MyExampleGeofenceCollection",
            description="A simple geofence collection"
        )

app = App()
MyLocationStack(app, "MyLocationServiceStack",
    env=Environment(
        account=os.environ.get("CDK_DEFAULT_ACCOUNT"),
        region=os.environ.get("CDK_DEFAULT_REGION"),
    )
)
app.synth()

view raw JSON →