gpt4 book ai didi

amazon-s3 - 使用 Cloudwatch 和 Cloudformation 拍摄计划的 EBS 快照

转载 作者:行者123 更新时间:2023-12-01 09:50:11 25 4
gpt4 key购买 nike

任务似乎很简单:我想每天为我的 EBS 卷拍摄计划的 EBS 快照。根据文档,CloudWatch 似乎是执行此操作的正确位置: http://docs.aws.amazon.com/AmazonCloudWatch/latest/events/TakeScheduledSnapshot.html

现在我想在使用 CloudFormation 启动新堆栈时创建这样的计划规则。为此,有一个新的资源类型 AWS::Events::Rule: http://docs.aws.amazon.com/AWSCloudFormation/latest/UserGuide/aws-resource-events-rule.html

但现在棘手的部分来了:如何使用此资源类型来创建一个内置目标来创建我的 EBS 快照,如上述场景中所述?

我很确定有办法做到这一点,但我现在无法控制自己。我的资源模板目前如下所示:

"DailyEbsSnapshotRule": {
"Type": "AWS::Events::Rule",
"Properties": {
"Description": "creates a daily snapshot of EBS volume (8 a.m.)",
"ScheduleExpression": "cron(0 8 * * ? *)",
"State": "ENABLED",
"Targets": [{
"Arn": { "Fn::Join": [ "", "arn:aws:ec2:", { "Ref": "AWS::Region" }, ":", { "Ref": "AWS::AccountId" }, ":volume/", { "Ref": "EbsVolume" } ] },
"Id": "SomeId1"
}]
}
}

有什么想法吗?

最佳答案

我在question about how to do this in terraform上找到了这个问题的解决方案。普通 CloudFormation JSON 中的解决方案似乎是。

"EBSVolume": {
"Type": "AWS::EC2::Volume",
"Properties": {
"Size": 1
}
},
"EBSSnapshotRole": {
"Type": "AWS::IAM::Role",
"Properties": {
"AssumeRolePolicyDocument": {
"Version" : "2012-10-17",
"Statement": [ {
"Effect": "Allow",
"Principal": {
"Service": ["events.amazonaws.com", "ec2.amazonaws.com"]
},
"Action": ["sts:AssumeRole"]
}]
},
"Path": "/",
"Policies": [{
"PolicyName": "root",
"PolicyDocument": {
"Version" : "2012-10-17",
"Statement": [ {
"Effect": "Allow",
"Action": [
"ec2:CreateSnapshot"
],
"Resource": "*"
} ]
}
}]
}
},
"EBSSnapshotRule": {
"Type": "AWS::Events::Rule",
"Properties": {
"Description": "creates a daily snapshot of EBS volume (1 a.m.)",
"ScheduleExpression": "cron(0 1 * * ? *)",
"State": "ENABLED",
"Name": {"Ref": "AWS::StackName"},
"RoleArn": {"Fn::GetAtt" : ["EBSSnapshotRole", "Arn"]},
"Targets": [{
"Arn": {
"Fn::Join": [
"",
[
"arn:aws:automation:",
{"Ref": "AWS::Region"},
":",
{"Ref": "AWS::AccountId"},
":action/",
"EBSCreateSnapshot/EBSCreateSnapshot_",
{"Ref": "AWS::StackName"}
]
]
},
"Input": {
"Fn::Join": [
"",
[
"\"arn:aws:ec2:",
{"Ref": "AWS::Region"},
":",
{"Ref": "AWS::AccountId"},
":volume/",
{"Ref": "EBSVolume"},
"\""
]
]
},
"Id": "EBSVolume"
}]
}
}

关于amazon-s3 - 使用 Cloudwatch 和 Cloudformation 拍摄计划的 EBS 快照,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/39042925/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com