Enabling and Disabling a S3 Replication Rule through api/cli

妖精的绣舞 提交于 2020-02-07 02:55:09

问题


I have set up a replication rule on my S3 bucket to populate a preprod bucket for testing purposes. This means I will want to be able to turn the replication on and off easily, and likely dump and refresh the replication bucket as necessary. I'm creating a script for this but am having a hard time finding a way to easily turn the replication rule on and off outside of using the AWS Console.

Is there an option beyond put-bucket-replication? That works but is basically restating the whole replication config each time, instead of just enabling or disabling the existing one.


回答1:


It looks like the only solution is to pass different put-bucket-replications with the Status as disabled or enabled. Example of disabled below using python and boto3:

import boto3

client = boto3.client('s3')

##Enable
client.put_bucket_replication(Bucket='yoursourcebucketname', ReplicationConfiguration={
    "Role": "arn:aws:iam::999999999:role/service-role/yourrolename",
    "Rules": [
        {
            "Status": "Disabled",
            "Priority": 1,
            "DeleteMarkerReplication": { "Status": "Disabled" },
            "Filter" : { "Prefix": ""},
            "Destination": {
                "Bucket": "arn:aws:s3:::yourlandingbucket",
                "Account": "838382828"
            }
        }
    ]
}
)


来源:https://stackoverflow.com/questions/57777622/enabling-and-disabling-a-s3-replication-rule-through-api-cli

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!