DynamoDB import_table 错误:“DynamoDB”对象没有属性“import_table”

问题描述 投票:0回答:1

我已成功完成将 S3 csv 导入 AWS 控制台中的新 dynamodb 表的步骤。但是,当尝试使用 boto3 时,我收到错误

'DynamoDB' object has no attribute 'import_table'
。通常您只需要设置表格,但由于
import_table
创建了一个新表格,我不确定需要什么。

我在导入之前使用

self.db_client
删除旧表,因为此导入将按照重复的时间表进行,但据我所知,这不会影响任何内容。

self.db_client = self.session.client("dynamodb")

def create_table_from_csv(self) -> dict:
        """Function to import csv from s3 to dynamodb
        Args:
            none
        Returns:

        """
        try:
            self.logger.info(
                "Import report from S3 to new dynamodb table: {}".format(
                    self.table_name
                )
            )
            response = self.db_client.import_table(
                S3BucketSource={
                    "S3Bucket": self.bucket_name,
                    "S3KeyPrefix": self.report_csv_key,
                },
                InputFormat="CSV",
                TableCreationParameters={
                    "TableName": self.table_name,
                    "AttributeDefinitions": [
                        {"AttributeName": "instanceArn", "AttributeType": "S"},
                        {"AttributeName": "instanceName", "AttributeType": "S"},
                    ],
                    "KeySchema": [
                        {"AttributeName": "instanceArn", "KeyType": "HASH"},
                        {"AttributeName": "instanceName", "KeyType": "Range"},
                    ],
                    "BillingMode": "PROVISIONED",
                    "ProvisionedThroughput": {
                        "ReadCapacityUnits": 5,
                        "WriteCapacityUnits": 5,
                    },
                    "SSESpecification": {
                        "Enabled": True,
                        "SSEType": "KMS",
                        "KMSMasterKeyId": self.table_key_arn,
                    },
                },
            )
        except ClientError as error:
            self.logger.error(
                "Error: failed to upload report({}) from s3 to new dynamodb table".format(
                    self.report_csv_key
                )
            )
            self.logger.error("Error message:" + str(error))

        return response

python-3.x amazon-web-services aws-lambda amazon-dynamodb boto3
1个回答
1
投票

您没有说明您正在使用哪个版本的 boto3。导入表功能已有大约 1 年历史,因此您应该确保使用最新的 boto3 软件包之一。

您的版本必须至少为 1.24.55

https://github.com/boto/boto3/blob/develop/CHANGELOG.rst#12455

© www.soinside.com 2019 - 2024. All rights reserved.