{"id":23311,"library":"aws-solutions-constructs-aws-iot-lambda","title":"AWS Solutions Constructs - IoT to Lambda","description":"AWS Solutions Constructs implementation of the aws-iot-lambda pattern. This CDK construct deploys an AWS IoT rule that routes messages from an IoT topic to an AWS Lambda function for processing. Current version: 2.101.0. Release cadence: aligns with AWS CDK releases, approximately every 2 weeks.","status":"active","version":"2.101.0","language":"python","source_language":"en","source_url":"https://github.com/awslabs/aws-solutions-constructs","tags":["aws","cdk","iot","lambda","serverless","construct"],"install":[{"cmd":"pip install aws-solutions-constructs-aws-iot-lambda","lang":"bash","label":"Install the construct"}],"dependencies":[{"reason":"Required as peer dependency for CDK constructs","package":"aws-cdk-lib","optional":false},{"reason":"Required for CDK construct base class","package":"constructs","optional":false}],"imports":[{"note":"Correct import path for the construct class","symbol":"IotToLambda","correct":"from aws_solutions_constructs.aws_iot_lambda import IotToLambda"},{"note":"Correct import path for the props class","symbol":"IotToLambdaProps","correct":"from aws_solutions_constructs.aws_iot_lambda import IotToLambdaProps"},{"note":"Incorrect nested import; the correct module is aws_iot_lambda at the top level","wrong":"from aws_solutions_constructs.aws_iot_lambda.aws_iot_lambda import IotToLambda","symbol":"IotToLambda"}],"quickstart":{"code":"from aws_cdk import App, Stack\nfrom aws_solutions_constructs.aws_iot_lambda import IotToLambda, IotToLambdaProps\nfrom aws_cdk.aws_lambda import Code, Runtime\nfrom aws_cdk.aws_iot import TopicRuleProps\n\napp = App()\nstack = Stack(app, \"test-iot-lambda-stack\")\n\n# Create the construct with a Lambda function from inline code\nIotToLambda(stack, \"test-iot-lambda\",\n    lambda_function_props={\n        \"runtime\": Runtime.PYTHON_3_9,\n        \"code\": Code.from_inline(\n            \"def handler(event, context):\\n    print(event)\\n\"\n        ),\n        \"handler\": \"index.handler\"\n    },\n    iot_topic_rule_props=TopicRuleProps(\n        topic_rule_name=\"my_rule\",\n        sql=\"SELECT * FROM 'device/#'\"\n    )\n)\n\napp.synth()","lang":"python","description":"Quick start: deploy an IoT rule that sends messages to a Lambda function."},"warnings":[{"fix":"Replace aws-cdk with aws-cdk-lib in your requirements and imports.","message":"CDK v2 migration: aws-solutions-constructs v2.x requires AWS CDK v2 and constructs v10.x. Ensure your project uses CDK v2 (aws-cdk-lib) and not the legacy CDK.","severity":"breaking","affected_versions":">=2.0.0"},{"fix":"Use 'lambda_function_props' (one underscore) instead of 'lambda_function_props' (two underscores).","message":"The 'lambda_function_props' parameter is deprecated in favor of 'lambda_function_props' (note the removed underscore after 'lambda'). Both work, but the correct property name is 'lambda_function_props' with one underscore.","severity":"deprecated","affected_versions":">=2.50.0"},{"fix":"To avoid orphaned buckets, set 'existingLambdaBucket' to a bucket with removal policy DESTROY or use 'autoDeleteObjects: true'.","message":"The construct silently creates an S3 bucket for Lambda code if you don't specify an existing bucket. This bucket is not automatically cleaned up on stack deletion unless you set 'existingLambdaBucket' explicitly.","severity":"gotcha","affected_versions":"all"}],"env_vars":null,"last_verified":"2026-05-01T00:00:00.000Z","next_check":"2026-07-30T00:00:00.000Z","problems":[{"fix":"Run: pip install aws-solutions-constructs-aws-iot-lambda. Then import: from aws_solutions_constructs.aws_iot_lambda import IotToLambda.","cause":"The package name uses hyphens but the import path uses underscores. Additionally, the module name is 'aws_iot_lambda' (not 'aws_iot_lambda').","error":"ModuleNotFoundError: No module named 'aws_solutions_constructs.aws_iot_lambda'"},{"fix":"Install with pip and use Python import: from aws_solutions_constructs.aws_iot_lambda import IotToLambda.","cause":"Trying to import the package directly in TypeScript-style (NPM). For Python, use pip and import via underscores.","error":"Error: Cannot find module 'aws-solutions-constructs-aws-iot-lambda'"},{"fix":"Change 'lambda_function_props' to 'lambda_function_props' (single underscore after 'lambda').","cause":"Using the deprecated 'lambda_function_props' parameter name (with two underscores). The correct parameter is 'lambda_function_props' with one underscore.","error":"TypeError: '__init__() got an unexpected keyword argument 'lambda_function_props''"}],"ecosystem":"pypi","meta_description":null,"install_score":null,"install_tag":null,"quickstart_score":null,"quickstart_tag":null}