View a markdown version of this page

Hello AWS IoT Greengrass V2 - AWS SDK Code Examples

There are more AWS SDK examples available in the AWS Doc SDK Examples GitHub repo.

Hello AWS IoT Greengrass V2

The following code example shows how to get started using AWS IoT Greengrass V2.

Python
SDK for Python (Boto3)
Note

There's more on GitHub. Find the complete example and learn how to set up and run in the AWS Code Examples Repository.

def hello_greengrassv2() -> None: """ Lists Greengrass core devices to verify connectivity to the service. Uses a paginator to handle pagination of results. """ greengrassv2_client = boto3.client("greengrassv2") print("\n----------- Welcome to AWS IoT Greengrass V2 ----------\n") print("Listing Greengrass core devices in your account...\n") try: devices = list() paginator = greengrassv2_client.get_paginator("list_core_devices") for page in paginator.paginate(): devices.extend(page.get("coreDevices", list())) if devices: print(f"Found {len(devices)} core device(s):") for device in devices: thing_name = device.get("coreDeviceThingName", "Unknown") status = device.get("status", "Unknown") last_updated = device.get("lastStatusUpdateTimestamp", "N/A") print( f" - {thing_name} (Status: {status}, Last updated: {last_updated})" ) else: print("No Greengrass core devices found in your account.") print( "To get started, install the Greengrass Core software on an IoT device." ) print("\nHello from AWS IoT Greengrass V2!") except ClientError as err: logger.error( "Error listing core devices: %s", err.response["Error"]["Message"], ) print(f"Service error: {err.response['Error']['Message']}") raise if __name__ == "__main__": hello_greengrassv2()
  • For API details, see ListCoreDevices in AWS SDK for Python (Boto3) API Reference.