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?

【AWS】エラー「type of argument max_allocated_storage must be one of (int, float, NoneType); got str instead」の原因

Posted at

概要

AWS CDKでRDSインスタンスを作成してcdk deployすると以下のエラーに。

TypeError: type of argument max_allocated_storage must be one of (int, float, NoneType); got str instead

原因と解決方法を紹介します。

原因と解決方法

エラーの原因は、max_allocated_storageに渡している値が文字列 (str) 型であるためでした。
メッセージにある通り、プロパティは数値 (intまたはfloat) 型にする必要があります。

以下のように変更すると、エラーが出なくなりました。

       rds_instance = rds.CfnDBInstance(
            self, "Sample-RDS",
            db_instance_identifier="sample-mysql8",
            db_instance_class="db.t3.micro",
            db_name=db_name,
            engine="mysql",
            engine_version="8.0.41",
            allocated_storage="20",
            max_allocated_storage=100, # intに変更
            db_subnet_group_name=rds_subnet_group.ref,
            vpc_security_groups=[rds_security_group.security_group_id],
            master_username=rds_secret.secret_value_from_json("username").unsafe_unwrap(),
            master_user_password=rds_secret.secret_value_from_json("password").unsafe_unwrap(),
            publicly_accessible=False,
        )

あれ、でも、allocated_storageint型にしなくても良いのはなぜだろう?と思い、AWS公式ドキュメントのCloudFormationのRDSリソース仕様を確認してみました。

すると、

AllocatedStorage: String

MaxAllocatedStorage: Integer

とあります。

AllocatedStorageMaxAllocatedStorageで期待している型が違う!?
これは知らなかった...

ということで、以上!

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?