create folder inside S3 bucket using Cloudformation

前端 未结 4 1485
死守一世寂寞
死守一世寂寞 2021-02-01 16:47

I\'m able to create an S3 bucket using cloudformation but would like to create a folder inside an S3 bucket..like

-->
<         


        
4条回答
  •  野趣味
    野趣味 (楼主)
    2021-02-01 17:08

    I ended up with a small python script. It should be run manually, but it does the the sync automatically. It's for lazy people who don't want to create a Lambda-Backed Custom Resource.

    import subprocess
    import json
    
    STACK_NAME = ...
    S3_RESOURCE = 
    LOCAL_DIR = 
    
    res = subprocess.run(
        ['aws', 'cloudformation', 'describe-stack-resource', '--stack-name', STACK_NAME, '--logical-resource-id', S3_RESOURCE],
        capture_output=True,
    )
    out = res.stdout.decode('utf-8')
    resource_details = json.loads(out)
    resource_id = resource_details['StackResourceDetail']['PhysicalResourceId']
    
    res = subprocess.run(
        ['aws', 's3', 'sync', LOCAL_DIR, f's3://{resource_id}/', '--acl', 'public-read']
    )
    
    

提交回复
热议问题