繁体   English   中英

如何将保存在 AWS S3 中的 CSV 导出到 DynamoDB?

[英]How do I export CSVs saved in AWS S3 to DynamoDB?

我看到可以将上传到 s3 的 CSV 直接导入到 dynamodb,但我还没有弄清楚如何正确地执行它。

我猜我的问题可能与我的分区键的命名与我的 csvs 中的实际标头有关,但我不确定。

有没有办法以编程方式轻松地将 CSV 从 s3 导入 dynamodb?

我有 20 个 CSV,我通过 Python 脚本上传到 S3:

import boto3

a_key = '...'
s_key = '...'
region = 'us-west-2'

def upload_to_aws(local_file, bucket, s3_file):
    s3 = boto3.client('s3', aws_access_key_id=a_key,
                          aws_secret_access_key=s_key, region_name=region)
    try:
        s3.upload_file(local_file, bucket, s3_file)
        print("Upload to Cloud Successful")
        return True
    except FileNotFoundError:
        print("The file was not found")
        return False

def snaps(team_name):
    uploaded = upload_to_aws(f'CSVs/{team_name}_snaps.csv', 'teamcsvs', f'CSVs/{team_name}_snaps.csv')

def short(team_name, short_year):
    uploaded = upload_to_aws(f'CSVs/{team_name}{short_year}.csv', 'teamcsvs', f'CSVs/{team_name}{short_year}.csv')

我遵循了本指南并希望我的 CSV 能够无缝地成为 dynamoDB 表,但我的导入一直失败。

我从日志中得到了一些不同的错误,但最新的是:

{
    "itemS3Pointer": {
        "bucket": "teamcsvs",
        "key": "CSVs/atl22.csv",
        "itemIndex": 0
    },
    "importArn": "arn:aws:dynamodb:us-west-2:874782694093:table/atl_snaps/import/01669752143020-2b8be4f0",
    "errorMessages": [
        "One or more parameter values were invalid: Value for Item.Score is ambiguous"
    ]
}
2022-11-29T13:04:57.021-07:00

Copy
{
    "itemS3Pointer": {
        "bucket": "teamcsvs",
        "key": "CSVs/atl22.csv",
        "itemIndex": 0
    },
    "importArn": "arn:aws:dynamodb:us-west-2:874782694093:table/atl_snaps/import/01669752143020-2b8be4f0",
    "errorMessages": [
        "One or more parameter values were invalid: Value for Item.Score is ambiguous"
    ]
}
{"itemS3Pointer":{"bucket":"teamcsvs","key":"CSVs/atl22.csv","itemIndex":0},"importArn":"arn:aws:dynamodb:us-west-2:874782694093:table/atl_snaps/import/01669752143020-2b8be4f0","errorMessages":["One or more parameter values were invalid: Value for Item.Score is ambiguous"]}
2022-11-29T13:04:57.021-07:00

Copy
{
    "itemS3Pointer": {
        "bucket": "teamcsvs",
        "key": "CSVs/atl22.csv",
        "itemIndex": 0
    },
    "importArn": "arn:aws:dynamodb:us-west-2:874782694093:table/atl_snaps/import/01669752143020-2b8be4f0",
    "errorMessages": [
        "One or more parameter values were invalid: Value for Item.Score is ambiguous"
    ]
}
{"itemS3Pointer":{"bucket":"teamcsvs","key":"CSVs/atl22.csv","itemIndex":0},"importArn":"arn:aws:dynamodb:us-west-2:874782694093:table/atl_snaps/import/01669752143020-2b8be4f0","errorMessages":["One or more parameter values were invalid: Value for Item.Score is ambiguous"]}
2022-11-29T13:04:57.021-07:00

Copy
{
    "itemS3Pointer": {
        "bucket": "teamcsvs",
        "key": "CSVs/atl22.csv",
        "itemIndex": 0
    },
    "importArn": "arn:aws:dynamodb:us-west-2:874782694093:table/atl_snaps/import/01669752143020-2b8be4f0",
    "errorMessages": [
        "One or more parameter values were invalid: Value for Item.Score is ambiguous"
    ]
}
{"itemS3Pointer":{"bucket":"teamcsvs","key":"CSVs/atl22.csv","itemIndex":0},"importArn":"arn:aws:dynamodb:us-west-2:874782694093:table/atl_snaps/import/01669752143020-2b8be4f0","errorMessages":["One or more parameter values were invalid: Value for Item.Score is ambiguous"]}

你没有得到一些不同的错误,你每次都会得到相同的错误。 Item.Score 不明确。

您能否分享您的 CSV 文件的片段,这将帮助我们确定问题。

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM