Lakeを使った実装 AthenaのView CREATE OR REPLACE VIEW "view_latest_status_security_hub_resource_findings" AS with resource_finding as ( select t1.finding.uid as finding_uid , t1.region , t1.account_id , max_by(t1.metadata.product.version, t1.finding.modified_time) as metadata_product_version , max_by(t1.metadata.product.feature.uid, t1.finding.modified_time) as metadata_product_feature_uid , max_by(t1.metadata.product.feature.name, t1.finding.modified_time) as compliance.status, t1.finding.modified_time) as compliance_status -- key-value <省略> , max_by(t1.state_id, t1.finding.modified_time) as state_id , max_by(t1.severity_id, t1.finding.modified_time) as severity_id , max_by(t1.unmapped, t1.finding.modified_time) as unmapped -- map from original_security_lake.security_hub as t1 cross join unnest(resources) as t(resource) where t1.region = 'ap-northeast-1' group by 1, 2, 3 )
Lakeを使った実装 AthenaのView select t1.finding_uid , t1.region , t1.account_id , t1.metadata_product_version <省略> , from_unixtime(t1.event_time / 1000) as event_at , regexp_replace(t1.unmapped['ProductFields'], '\\n?') as unmapped_product_fields , t1.unmapped['NetworkPath'] as unmapped_network_path , t2.name as aws_account_name , t2.company_name as aws_account_company_name , t2.business_unit_name as aws_account_business_unit_name from resource_finding as t1 inner join business_budget."aws_accounts" as t2 on t1.account_id = t2.id where (t1.compliance_status not in('PASSED', 'NOT_AVAILABLE') or t1.compliance_status is null) and t2.company_name = 'Gunosy Inc.' and from_unixtime(t1.finding_modified_time / 1000) >= current_timestamp - interval '2' day