0
0

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?

DuckDB で IAM Identity Center(旧:AWS SSO) を使って認証しつつ S3 にクエリを投げる

Last updated at Posted at 2025-01-10

~/.aws/config はこんな感じ。

~/.aws/config
[profile my-sso-profile]
sso_start_url  = https://<MY_AWS_ACCOUNT>.awsapps.com/start
sso_region     = <MY_AWS_SSO_REGION>
sso_account_id = <MY_AWS_SSO_ACCOUNT_ID>
sso_role_name  = <MY_AWS_SSO_ROLE_NAME>
region         = ap-northeast-1
output         = json

duckdb 実行前に AWS SSO の profile を指定して aws sso login を実行しておく。

$ aws sso login --profile=my-sso-profile
$ duckdb
v1.1.3 19864453f7
Enter ".help" for usage hints.
Connected to a transient in-memory database.
Use ".open FILENAME" to reopen on a persistent database.
INSTALL aws;
LOAD aws;
INSTALL httpfs;
LOAD httpfs;

CREATE SECRET (
    TYPE S3,
    PROVIDER credential_chain,
    CHAIN 'sso',
    PROFILE 'my-sso-profile'
);

これで S3 の任意のバケット上のオブジェクトにクエリが投げられるようになる。
例えば、Cost and Usage Report の月次データを参照して、AWS の費用分析を出来たりする。

SELECT * FROM read_csv('s3://<MY_AWS_USAGE_REPORT>/report/daily/20241201-20250101/daily-00001.csv.gz') limit 3;

┌──────────────────────┬──────────────────────┬────────────────┬───┬──────────────────────┬──────────────────────┐
│ identity/LineItemId  │ identity/TimeInter…  │ bill/InvoiceId │ … │ resourceTags/user:…  │ resourceTags/user:…  │
│       varchar        │       varchar        │    varchar     │   │       varchar        │       boolean        │
├──────────────────────┼──────────────────────┼────────────────┼───┼──────────────────────┼──────────────────────┤
│ aaaaaaaaaaaaaaaaaa…  │ 2024-12-17T00:00:0…  │ JPAA11-1111    │ … │                      │                      │
│ bbbbbbbbbbbbbbbbbb…  │ 2024-12-28T00:00:0…  │ JPBB22-2222    │ … │                      │                      │
│ cccccccccccccccccc…  │ 2024-12-09T00:00:0…  │ JPCC33-3333    │ … │                      │                      │
├──────────────────────┴──────────────────────┴────────────────┴───┴──────────────────────┴──────────────────────┤
│ 3 rows                                                                                   274 columns (5 shown) │
└────────────────────────────────────────────────────────────────────────────────────────────────────────────────┘

274カラムもあって気が遠くなりましたがそういうもんです。歯を食いしばりましょう。

ref

0
0
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
0
0

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?