1
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 s3

Posted at
# variable.py
buckets_info = [
    {
        "name": "my-s3-bucket-1",
        "lifecycle_rules": [
            {
                "id": "expire_objects",
                "enabled": True,
                "expiration_days": 8,
            }
        ],
    },
    {
        "name": "my-s3-bucket-2",
        "lifecycle_rules": [
            {
                "id": "expire_objects",
                "enabled": True,
                "expiration_days": 8,
            }
        ],
    },
    # 添加更多桶的配置...
]
# s3_module.py
from cdktf import App, TerraformStack
from constructs import Construct
from imports.aws import AwsProvider, s3
import variable

class MyS3Buckets(TerraformStack):
    def __init__(self, scope: Construct, ns: str):
        super().__init__(scope, ns)
        
        AwsProvider(self, "AWS", region="us-east-1")
        
        # 根据 variable.py 中定义的信息创建多个 S3 桶
        for bucket_info in variable.buckets_info:
            s3.Bucket(self,
                      bucket_info["name"],
                      bucket=bucket_info["name"],
                      lifecycle_rule=bucket_info["lifecycle_rules"],
                      versioning=[s3.BucketVersioningArgs(
                          enabled=False
                      )])

app = App()
MyS3Buckets(app, "my-s3-buckets")
app.synth()
1
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
1
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?