cloudtools / troposphere

troposphere - Python library to create AWS CloudFormation descriptions
BSD 2-Clause "Simplified" License
4.93k stars 1.45k forks source link

How use deletionPolicy in s3Bucket? #378

Closed ismaelfernandezscmspain closed 8 years ago

ismaelfernandezscmspain commented 8 years ago

Hi,

I would like to use DeletionPolicy in a s3 bucket, I have the nex code: def s3_bucket(self, template_cf): 159 s3bucket = Bucket("S3Bucket") 160 s3bucket.AccessControl = PublicRead 161 s3bucket.VersioningConfiguration = VersioningConfiguration(Status="Enabled") 162 s3bucket.BucketName = "vibber-registry-dockerimages-vibbor" 163 164 template_cf.add_resource(s3bucket,DeletionPolicy=Retain) 165 template_cf.add_output(Output( 166 "BucketName", 167 Value=Ref(s3bucket), Description="Name of S3 bucket to hold website content" ))

And the output for this is: TypeError: add_resource() got an unexpected keyword argument 'DeletionPolicy'

Regards,

markpeek commented 8 years ago

If you're doing individual attribute assignments:

>>> from troposphere.s3 import Bucket
>>> s3bucket = Bucket("S3Bucket")
>>> s3bucket.DeletionPolicy=Retain
>>> t = Template()
>>> t.add_resource(s3bucket)
<troposphere.s3.Bucket object at 0x1028068d0>
>>> print t.to_json()
{
    "Resources": {
        "S3Bucket": {
            "DeletionPolicy": "Retain",
            "Type": "AWS::S3::Bucket"
        }
    }
}
ismaelfernandezscmspain commented 8 years ago

Hi, I solve the problem with: s3bucket = Bucket("S3bucket", DeletionPolicy="Retain")

I try to fix my problem do "s3bucket.DeletionPolicy=Retain", but I've had this error: AttributeError: AWS::S3::Bucket object does not support attribute DeletionPolicy

regards,