- Newest
- Most votes
- Most comments
To implement dynamic partitioning in Firehose based on the field .detail.body.events[0].enrichedEventData.vatNo from your sample event, you can use Firehose's built-in data transformation capabilities without resorting to a Lambda function. Here's an approach you can take:
-
Enable dynamic partitioning when setting up your Firehose delivery stream to Amazon S3.
-
For the partitioning key, you'll need to use a JQ expression to extract the desired field. Given the nested structure of your JSON, you can use the following JQ expression:
(.detail.body | fromjson).events[0].enrichedEventData.vatNo
This expression first parses the "body" field (which is a string containing JSON) using the
fromjsonfunction, then navigates to the desired "vatNo" field. -
Set up your S3 bucket prefix to use this partitioning key. For example:
vatNo=!{partitionKeyFromQuery:vatNo}/year=!{timestamp:yyyy}/month=!{timestamp:MM}/day=!{timestamp:dd}/
This approach will partition your data in S3 based on the VAT number, as well as by year, month, and day.
To handle potential errors:
-
Ensure you specify an S3 error bucket prefix when creating your Firehose stream. This is mandatory when enabling dynamic partitioning.
-
If some records fail to be partitioned (e.g., due to missing or malformed data), they will be delivered to this error bucket. You can then analyze these records to identify and resolve any issues.
-
Consider using a default value in your JQ expression to handle cases where the VAT number might be missing:
((.detail.body | fromjson).events[0].enrichedEventData.vatNo // "unknown")
This will use "unknown" as the partition key if the VAT number is not present.
By using this approach, you can implement dynamic partitioning directly in Firehose without the need for a Lambda function, while also handling potential errors and edge cases in your data.
Sources
Partition streaming data in Amazon Data Firehose - Amazon Data Firehose
Enable dynamic partitioning in Amazon Data Firehose - Amazon Data Firehose
Amazon Kinesis Data Firehose FAQs - Streaming Data Pipeline - Amazon Web Services
Troubleshoot dynamic partitioning errors - Amazon Data Firehose
Kinesis Firehose Dynamic Partitoning with inline jq expression | AWS re:Post
Relevant content
asked 3 years ago
asked 2 years ago
- AWS OFFICIALUpdated 10 months ago

Thank you for your answer. I want to set this in my template.yaml but I got an error (#: extraneous key [DynamicPartitioningConfiguration] is not permitted) BusinessDPTransactionsFirehose: Type: AWS::KinesisFirehose::DeliveryStream Properties: DeliveryStreamName: !Join - '-' - - !Ref AWS::StackName - 'dp' - businessTransactionsDeliveryStream DeliveryStreamType: DirectPut S3DestinationConfiguration: BucketArn: !GetAtt BusinessTransactionsBucket.Arn RoleArn: !GetAtt FireHoseToS3BucketRole.Arn Prefix: "vatNo=!{partitionKeyFromQuery:vatNo}/" ErrorOutputPrefix: "error/" BufferingHints: # needs to be in between 60 and 900, 60 to have faster results in S3 for testing IntervalInSeconds: 60 # needs to be between 1 and 128, maximum right now because intervalInSeconds will allow fast delivery during testing SizeInMBs: 128 DynamicPartitioningConfiguration: Enabled: true RetryOptions: DurationInSeconds: 300 ProcessingConfiguration: Enabled: true Processors: - Type: MetadataExtraction Parameters: - ParameterName: MetadataExtractionQuery ParameterValue: "(.detail.body | fromjson).events[0].enrichedEventData.vatNo" - ParameterName: JsonParsingEngine ParameterValue: "JQ-1.6"