AWSTimestream表无法写入ResourceNotFound异常
创始人
2024-09-27 15:30:31
0

解决此问题的可能原因是在代码中使用了错误的表名或没有创建该表。确保在代码中使用正确的表名,或使用AWS Timestream SDK等工具创建该表。

以下是一个使用AWS Timestream SDK创建表并将数据写入表的示例代码:

import boto3
from botocore.exceptions import ClientError

# 创建AWS Timestream客户端
client = boto3.client('timestream-write')

# 创建表
database_name = 'your_database_name'
table_name = 'your_table_name'
dimensions = [{'Name': 'region', 'Value': 'us-west-2'}, {'Name': 'az', 'Value': 'az1'}]
retention_properties = {'MemoryStoreRetentionPeriodInHours': 24, 'MagneticStoreRetentionPeriodInDays': 7}
try:
    response = client.create_table(DatabaseName=database_name, TableName=table_name, RetentionProperties=retention_properties, Dimensions=dimensions)
    print(f'创建表成功:{response}')
except ClientError as e:
    if e.response['Error']['Code'] == 'ConflictException':
        print(f'表已经存在:{table_name}')
    else:
        print(f'创建表失败:{e}')

# 写入数据
dimensions = [{'Name': 'region', 'Value': 'us-west-2'}, {'Name': 'az', 'Value': 'az1'}]
measure_name = 'cpu_utilization'
measure_value = '13.5'
measure_unit = 'Percent'
time = '2022-01-01T00:00:00Z'
try:
    response = client.write_records(DatabaseName=database_name, TableName=table_name, Records=[{'Dimensions': dimensions, 'MeasureName': measure_name, 'MeasureValue': measure_value, 'MeasureValueType': 'DOUBLE', 'Time': time, 'TimeUnit': 'SECONDS', 'Version': 1}])
    print(f'写入数据成功:{response}')
except ClientError as e:
    print(f'写入数据失败:{e}')

在此示例中,使用boto3库创建AWS Timestream客户端,在Timestream中创建表并将数据写入表。

相关内容

热门资讯

透视普及!wepoker有辅助... 透视普及!wepoker有辅助功能吗(透视)wpk德州局透视,教程窍要(有挂助手)-哔哩哔哩1、we...
透视推荐!云扑克有透视吗(透视... 透视推荐!云扑克有透视吗(透视)wepokerplus万能挂,教程诀窍(有挂规律)-哔哩哔哩1、该软...
透视解谜!拱趴大菠萝机器人(透... 透视解谜!拱趴大菠萝机器人(透视)wpk辅助是什么,教程法门(有挂秘诀)-哔哩哔哩1、游戏颠覆性的策...
透视详细!aa poker透视... 透视详细!aa poker透视软件(透视)红龙poker辅助,教程大纲(有挂存在)-哔哩哔哩1、aa...
透视科普!wepoker透视视... 透视科普!wepoker透视视频(透视)wepoker透视脚本免费下载,教程机巧(有挂方略)-哔哩哔...
透视曝光!wepoker辅助器... 透视曝光!wepoker辅助器如何使用(透视)wepoker透视器免费,教程手段(有挂技巧)-哔哩哔...
透视推荐!德州局怎么透视(透视... 透视推荐!德州局怎么透视(透视)wejoker辅助软件,教程法门(有挂神器)-哔哩哔哩1、完成德州局...
透视开挂!哈糖大菠萝万能挂(透... 透视开挂!哈糖大菠萝万能挂(透视)wpk辅助哪里买,教程积累(有挂辅助)-哔哩哔哩1、玩家可以在哈糖...
透视解迷!如何下载wpk透视版... 透视解迷!如何下载wpk透视版(透视)wepoker是不是有人用挂,教程方针(有挂分析)-哔哩哔哩1...
透视推荐!wpk可以透视吗(透... 透视推荐!wpk可以透视吗(透视)pokemmo脚本辅助器,教程积累(详细教程)-哔哩哔哩1、上手简...