@@ -544,13 +544,13 @@ async fn purify_create_sink(
544544 }
545545 }
546546 CreateSinkConnection :: Iceberg {
547- connection ,
547+ catalog_connection ,
548548 aws_connection,
549549 ..
550550 } => {
551551 let scx = StatementContext :: new ( None , & catalog) ;
552552 let connection = {
553- let item = scx. get_item_by_resolved_name ( connection ) ?;
553+ let item = scx. get_item_by_resolved_name ( catalog_connection ) ?;
554554 // Get Iceberg connection
555555 match item. connection ( ) ? {
556556 Connection :: IcebergCatalog ( connection) => {
@@ -563,63 +563,72 @@ async fn purify_create_sink(
563563 }
564564 } ;
565565
566- let aws_conn_id = aws_connection. item_id ( ) ;
567-
568- let aws_connection = {
569- let item = scx. get_item_by_resolved_name ( aws_connection) ?;
570- // Get AWS connection
571- match item. connection ( ) ? {
572- Connection :: Aws ( aws_connection) => aws_connection. clone ( ) ,
573- _ => sql_bail ! (
574- "{} is not an aws connection" ,
575- scx. catalog. resolve_full_name( item. name( ) )
576- ) ,
577- }
578- } ;
566+ // Validate the sink's (optional) AWS connection even though we never use it.
567+ // TODO(kynan): If we do start using the sink's creds, check again that this validation
568+ // accurately reflects what we need.
569+ // Consider rolling the storage creds validation into the catalog connection's "connect" fn,
570+ // which already validates the catalog creds (currently also used for the storage layer).
571+ if let Some ( aws_connection) = aws_connection {
572+ let aws_conn_id = aws_connection. item_id ( ) ;
573+ let aws_connection = {
574+ let item = scx. get_item_by_resolved_name ( aws_connection) ?;
575+ // Get AWS connection
576+ match item. connection ( ) ? {
577+ Connection :: Aws ( aws_connection) => aws_connection. clone ( ) ,
578+ _ => sql_bail ! (
579+ "{} is not an aws connection" ,
580+ scx. catalog. resolve_full_name( item. name( ) )
581+ ) ,
582+ }
583+ } ;
579584
580- // For S3 Tables connections in the Materialize Cloud product, verify the
581- // AWS region matches the environment's region. This check only applies when
582- // the enable_s3_tables_region_check dyncfg is set.
583- if let Some ( s3tables) = connection. s3tables_catalog ( ) {
584- let enable_region_check =
585- ENABLE_S3_TABLES_REGION_CHECK . get ( scx. catalog . system_vars ( ) . dyncfgs ( ) ) ;
586- if enable_region_check {
587- let env_id = & catalog. config ( ) . environment_id ;
588- if matches ! ( env_id. cloud_provider( ) , CloudProvider :: Aws ) {
589- let env_region = env_id. cloud_provider_region ( ) ;
590- // Later on we default to "us-east-1" if the region is not set on the S3 Tables
591- // connection, so we need to do the same check here.
592- let s3_tables_region = s3tables
593- . aws_connection
594- . connection
595- . region
596- . clone ( )
597- . unwrap_or_else ( || "us-east-1" . to_string ( ) ) ;
598- if s3_tables_region != env_region {
599- Err ( IcebergSinkPurificationError :: S3TablesRegionMismatch {
600- s3_tables_region,
601- environment_region : env_region. to_string ( ) ,
602- } ) ?;
585+ // For S3 Tables connections in the Materialize Cloud product, verify the
586+ // AWS region matches the environment's region. This check only applies when
587+ // the enable_s3_tables_region_check dyncfg is set.
588+ if let Some ( s3tables) = connection. s3tables_catalog ( ) {
589+ let enable_region_check =
590+ ENABLE_S3_TABLES_REGION_CHECK . get ( scx. catalog . system_vars ( ) . dyncfgs ( ) ) ;
591+ if enable_region_check {
592+ let env_id = & catalog. config ( ) . environment_id ;
593+ if matches ! ( env_id. cloud_provider( ) , CloudProvider :: Aws ) {
594+ let env_region = env_id. cloud_provider_region ( ) ;
595+ // Later on we default to "us-east-1" if the region is not set on the S3 Tables
596+ // connection, so we need to do the same check here.
597+ let s3_tables_region = s3tables
598+ . aws_connection
599+ . connection
600+ . region
601+ . clone ( )
602+ . unwrap_or_else ( || "us-east-1" . to_string ( ) ) ;
603+ if s3_tables_region != env_region {
604+ Err ( IcebergSinkPurificationError :: S3TablesRegionMismatch {
605+ s3_tables_region,
606+ environment_region : env_region. to_string ( ) ,
607+ } ) ?;
608+ }
603609 }
604610 }
605611 }
612+
613+ let _sdk_config = aws_connection
614+ . load_sdk_config (
615+ & storage_configuration. connection_context ,
616+ aws_conn_id. clone ( ) ,
617+ InTask :: No ,
618+ mz_storage_types:: dyncfgs:: ENFORCE_EXTERNAL_ADDRESSES
619+ . get ( storage_configuration. config_set ( ) ) ,
620+ )
621+ . await
622+ . map_err ( |e| IcebergSinkPurificationError :: AwsSdkContextError ( Arc :: new ( e) ) ) ?;
606623 }
607624
625+ // Now that we've validated the sink's storage creds (if they exist)
626+ // we _could_ use them to build a complete Iceberg client (both catalog and storage).
627+ // TODO(kynan): Actually use those sink-specific creds here instead of ignoring them.
608628 let _catalog = connection
609629 . connect ( storage_configuration, InTask :: No )
610630 . await
611631 . map_err ( |e| IcebergSinkPurificationError :: CatalogError ( Arc :: new ( e) ) ) ?;
612-
613- let _sdk_config = aws_connection
614- . load_sdk_config (
615- & storage_configuration. connection_context ,
616- aws_conn_id. clone ( ) ,
617- InTask :: No ,
618- mz_storage_types:: dyncfgs:: ENFORCE_EXTERNAL_ADDRESSES
619- . get ( storage_configuration. config_set ( ) ) ,
620- )
621- . await
622- . map_err ( |e| IcebergSinkPurificationError :: AwsSdkContextError ( Arc :: new ( e) ) ) ?;
623632 }
624633 }
625634
0 commit comments