タダです.
re:Invent 中に S3 Vectors が GA されました.東京リージョンにもきており,Terraform aws provider v6.24.0 で S3 Vectors のサポートが入っているため試してみます.
リリース概要
v6.24.0 では次の S3 Vectors のリソースがサポートされました.
- aws_s3vectors_vector_bucket: ベクトルデータを格納するバケット
- aws_s3vectors_vector_bucket_policy: 上記ベクトルバケットに対するアクセスポリシー管理
- aws_s3vectors_index: ベクトル検索用のインデックスリソース
これらのリソースを東京リージョンで定義して使ってみましょう.
Terraform で S3 Vectors を定義する
以前書いた記事をベースにリソースを作ります.
resource "aws_s3vectors_vector_bucket" "blog" { vector_bucket_name = "blog-s3-vectors" } resource "aws_s3vectors_index" "blog" { index_name = "blog-s3-vectors-index" vector_bucket_name = aws_s3vectors_vector_bucket.blog.vector_bucket_name data_type = "float32" dimension = 1024 distance_metric = "cosine" }
この定義ですと次のような実行計画ができるので作成します.
Terraform will perform the following actions: # aws_s3vectors_index.blog will be created + resource "aws_s3vectors_index" "blog" { + creation_time = (known after apply) + data_type = "float32" + dimension = 1024 + distance_metric = "cosine" + encryption_configuration = (known after apply) + index_arn = (known after apply) + index_name = "blog-s3-vectors-index" + region = "ap-northeast-1" + tags_all = {} + vector_bucket_name = "blog-s3-vectors" } # aws_s3vectors_vector_bucket.blog will be created + resource "aws_s3vectors_vector_bucket" "blog" { + creation_time = (known after apply) + encryption_configuration = (known after apply) + force_destroy = false + region = "ap-northeast-1" + tags_all = {} + vector_bucket_arn = (known after apply) + vector_bucket_name = "blog-s3-vectors" } Plan: 2 to add, 0 to change, 0 to destroy. Do you want to perform these actions? Terraform will perform the actions described above. Only 'yes' will be accepted to approve. Enter a value: yes aws_s3vectors_vector_bucket.blog: Creating... aws_s3vectors_vector_bucket.blog: Creation complete after 0s aws_s3vectors_index.blog: Creating... aws_s3vectors_index.blog: Creation complete after 0s Apply complete! Resources: 2 added, 0 changed, 0 destroyed.
作成されたリソースが作成できたかを AWS CLI を使って確認したところ意図通り東京リージョンにリソースが存在してました.
# バケットの確認 ❯ aws s3vectors list-vector-buckets --region ap-northeast-1 { "vectorBuckets": [ { "vectorBucketName": "blog-s3-vectors", "vectorBucketArn": "arn:aws:s3vectors:ap-northeast-1:1234567891011:bucket/blog-s3-vectors", "creationTime": "2025-12-14T12:34:42+09:00" } ] } # インデックスの確認 ❯ aws s3vectors get-index --vector-bucket-name blog-s3-vectors --index-name blog-s3-vectors-index --region ap-northeast-1 { "index": { "vectorBucketName": "blog-s3-vectors", "indexName": "blog-s3-vectors-index", "indexArn": "arn:aws:s3vectors:ap-northeast-1:1234567891011:bucket/blog-s3-vectors/index/blog-s3-vectors-index", "creationTime": "2025-12-14T12:34:43+09:00", "dataType": "float32", "dimension": 1024, "distanceMetric": "cosine" } }
S3 Vectors にテストデータを投入する
テストデータを投入し,検索してみます.テストデータは以下のように生成して S3 Vectors にアップロードします.
❯ cat input.json { "inputText": "This is test vector data." } ❯ aws bedrock-runtime invoke-model --model-id "amazon.titan-embed-text-v2:0" --body fileb://input.json --content-type application/json --accept application/json --region ap-northeast-1 output.json { "contentType": "application/json" } ❯ jq -c '.embedding' output.json > vector_data.json ❯ cat <<EOF > vector_upload.json ∙ [ { "key": "doc1", "data": { "float32": $(cat vector_data.json) }, "metadata": { "source_text": "This is test vector data.", "category": "test" } } ] ∙ EOF ❯ aws s3vectors put-vectors --vector-bucket-name blog-s3-vectors --index-name blog-s3-vectors-index --vectors file://vector_upload.json --region ap-northeast-1
投入したデータを検索します.意図通りに検索できました.
❯ jq '{float32: .embedding}' output.json > embedding.json ❯ aws s3vectors query-vectors --vector-bucket-name blog-s3-vectors --index-name blog-s3-vectors-index --top-k 3 --query-vector file://embedding.json --return-metadata --region ap-northeast-1 { "vectors": [ { "key": "doc1", "metadata": { "category": "test", "source_text": "This is test vector data." } } ], "distanceMetric": "cosine" }
まとめ
GA された S3 Vectors を Terraform でリソース管理を試してメモをまとめました.