Using the example from here. I can create a table and lambda function that has access to the table. But I need to know the name of table to use table.put to add records.
Short term I am declaring the table name in the dynamo_table_props and then exporting it to the lambda as an environment variable. However, this is against the best practices to declare names.
I've tried to access the pattern properties, but cannot find the correct syntax.
What I have working is:
from aws_solutions_constructs.aws_iot_lambda_dynamodb import IotToLambdaToDynamoDB
from aws_cdk import (
aws_iot as iot,
aws_lambda as _lambda,
Stack
)
from constructs import Construct
IotToLambdaToDynamoDB(self, 'test-iot-lambda-dynamodb-stack',
lambda_function_props=_lambda.FunctionProps(
code=_lambda.Code.from_asset('lambda'),
runtime=_lambda.Runtime.PYTHON_3_9,
handler='index.handler',
environment={
'TABLE_NAME':'hard_coded_table_name'
},
),
iot_topic_rule_props=iot.CfnTopicRuleProps(
topic_rule_payload=iot.CfnTopicRule.TopicRulePayloadProperty(
rule_disabled=False,
description="Processing of DTC messages from the AWS Connected Vehicle Solution.",
sql="SELECT * FROM 'connectedcar/dtc/#'",
actions=[]
)
),
dynamo_table_props=ddb.TableProps(
partition_key={'name': 'id', 'type': ddb.AttributeType.STRING},
table_name='hard_coded_table_name'))