I'm trying to work with the AWS CDK for DynamoDB and am finding the documentation examples somewhat limited. I'm trying to create a specific DynamoDB table that gets a Timestamp attached to the table being created via AWS CDK. I tried finding examples of something that accomplishes this by referring to this but am not able to find something close.
Below is my code that creates a table, but I need a timestamp to be attached to the table being created. I believe a working solution for what I am trying to do can consist of taking the value I have specified in "table_name" and concatenating the timeStamp variable with the value for "table_name". My python knowledge is somewhat limited. Any advice on how I can concatenate these values would be helpful. I think that should work.
from aws_cdk import (
core as cdk,
aws_dynamodb as dynamodb
)
from aws_cdk import core
from datetime import datetime
class CdkStack(cdk.Stack):
def __init__(self, scope: cdk.Construct, construct_id: str, **kwargs) -> None:
super().__init__(scope, construct_id, **kwargs)
currentDate= dateTime.now()
timeStamp= dateTime.timestamp(currentDate)
dynamodbTable= dynamodb.Table(self,id='dynamodbTable',table_name='DynamoDbTableWithTimeStamp',partition_key=dynamodb.Attribute(name='id',type=dynamodb.AttributeType.STRING))
Looks like simple string formatting is what you need:
import time
...
table_name=f'DynamoDbTableWithTimeStamp_{int(time.time())}',
...
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.