跳至內容

Loading data into DynamoDB by using Glue Studio, resulting in Provided list of item keys contains duplicates

0

Hi,

I have to load a file containing some postal codes (around 200.000, CSV), stored onto S3, to a DynamoDB table. I'm following two approaches, on based on Lambda, one based on Glue Studio.

In the Glue Studio case, the graph is pretty simple, based on two nodes, where the first one loads the data from S3 and the second one specifies the writing option into a custom node ; the primary key being the postal code, without sorting key. As following :

glueContext.write_dynamic_frame_from_options( frame=dfc, connection_type="dynamodb", connection_options={ "dynamodb.output.tableName": "postalCodes" } )

Moreover, the run fails systematically after inserting the first 50 entries and with the error: Provided list of item keys contains duplicates. But, the original list doesn't contain any duplicate.

So, what is the point I've missed?

Thanks in advance,

Fred

已提問 5 年前檢視次數 2926 次

2 個答案
3
已接受的答案

Hi Fred,

As you may know Glue Connection to DynamoDB is an abstraction on BatchWriteItems API call for DynamoDB, wherein it writes in batches of 25 items per request. As you are using postal_code as the partition key, if two items in a batch of 25 items contain the same postal_code, then you will receive this exception.

Before writing out to sink, you could convert your DynamicFrame to a Dataframe and call either distinct or dropDuplicates on the postal_code column. You must then convert back to DynamicFrame to make use of DynamoDB as a sink.

df
  .select("postal_code")
  .distinct
  .withColumn("postal_code","other", "other1"))
  .show()

Another thing worth checking is that you are not reading in CSV headers, this could also be the cause of having duplicates in the same batch. You can set the option when reading the CSV with the following param:

'withHeader': False

AWS
專家

已回答 5 年前

專家

已審閱 2 年前

0

Hi Leeroy, thanks for the point. So, we realized the deduplicate stage doesn't work well under certain conditions. We reinforced it and our Glue process works well now. Best regards, Fred

已回答 5 年前

您尚未登入。 登入 去張貼答案。

一個好的回答可以清楚地回答問題並提供建設性的意見回饋,同時有助於提問者的專業成長。