Skip to content

Commit

Permalink
update populate
Browse files Browse the repository at this point in the history
  • Loading branch information
tinhtq committed Dec 20, 2024
1 parent 35410fb commit d626c3f
Show file tree
Hide file tree
Showing 3 changed files with 31 additions and 2 deletions.
2 changes: 2 additions & 0 deletions dynamodb/populate-data/lambda/main.py
Original file line number Diff line number Diff line change
Expand Up @@ -76,3 +76,5 @@ def lambda_handler(event, context):
"statusCode": 200,
"body": json.dumps("200 items successfully inserted into DynamoDB"),
}

lambda_handler("","")
2 changes: 0 additions & 2 deletions dynamodb/populate-data/main.tf
Original file line number Diff line number Diff line change
@@ -1,5 +1,3 @@


resource "aws_dynamodb_table" "global_table" {
name = var.table_name
billing_mode = "PAY_PER_REQUEST"
Expand Down
29 changes: 29 additions & 0 deletions dynamodb/populate-data/script/get_data_dynamodb_stream.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
import boto3

dynamodb_client = boto3.client('dynamodb')

# Get the stream ARN from your table
table_name = "MyGT"
response = dynamodb_client.describe_table(TableName=table_name)
stream_arn = response['Table']['LatestStreamArn']

print(stream_arn)
# Get the shard iterator
streams_client = boto3.client('dynamodbstreams')
stream_response = streams_client.describe_stream(StreamArn=stream_arn)
shard_id = stream_response['StreamDescription']['Shards'][0]['ShardId']

shard_iterator_response = streams_client.get_shard_iterator(
StreamArn=stream_arn,
ShardId=shard_id,
ShardIteratorType='TRIM_HORIZON'
)

shard_iterator = shard_iterator_response['ShardIterator']
while True:
records_response = streams_client.get_records(ShardIterator=shard_iterator)
for record in records_response['Records']:
print(record)

# Update shard iterator for the next loop
shard_iterator = records_response['NextShardIterator']

0 comments on commit d626c3f

Please sign in to comment.