##### Global variables ####
region="us-east-2"
instance_type="t2.micro"
ebs_volume_size="20"
meta_template_name="ec2_policy_meta_template"
###############################
start_time_1 = input("What's the start time")
end_time1 = input("What's the end time")
def create_aws_iam_policy_template(**kwargs):
template_data = {}
template_data["region"] = kwargs.get('region')
template_data["start_time"] = kwargs.get('end_time')
template_data["end_time"] = kwargs.get('start_time')
template_data["instance_type"] = kwargs.get('instance_type')
template_data["ebs_volume_size"] = kwargs.get('ebs_volume_size')
template_data["meta_template_name"] = kwargs.get('meta_template_name')
meta_template_dict = getattr(meta_templates, template_data["meta_template_name"])
meta_template_json = json.dumps(meta_template_dict)
template_json = Template(meta_template_json).render(template_data)
return template_json
template_json = create_aws_iam_policy_template(
region=region,
instance_type=instance_type,
ebs_volume_size=ebs_volume_size,
meta_template_name=meta_template_name,
start_time = start_time_1,
end_time = end_time1
)
app_json = json.dumps(template_json)
print(app_json)
“{”版本“:”2012-10-17“、”语句“:[{”SID“:”VisualEditor0“、”Effect“:”Allow“、”Action“:”EC2:RunInstances“、”Resource“:[”arn:aws:ec2:us-East-2:::Instance/“、”arn:aws:ec2:us-East-2::Network-Interface/“、”arn:aws:ec2:us-East-2::Key-pair/“、”arn:aws:ec2:us-East-2::Security-Group/“、”arn:aws:ec2:us-East-2::Volume/“”,“arn:aws:ec2:us-East-2::Image/AMI-”],“condition”:{“ForAllValues:NumericLessThanequals”:{“ec2:VolumeSize”:“20”},“ForAllValues:StringEquals”:{“ec2:InstanceType”:“T2.Micro”}}},{“SID”:“VisualEditor1”,“Effect”:“Allow”,“Action”:[“ec2:TerminateInstances”,“ec2:StartInstances”,“ec2:StopInstances”],“Resource”:“arn:aws:ec2:us-East-2::Instance/”,“condition”:{“ForAllValues:StringEquals”:{“ec2:InstanceType”:“t2.micro”}}},{“sid”:“VisualEditor2”,“Effect”:“Allow”,“Action”:[“ec2:Descripe*”,“ec2:GetConsole*”,“CloudWatch:DescripeAlarms”,“IAM:ListInstanceProfiles”,“CloudWatch:GetMetricStatistics”,“ec2:DescripeKeyPairs”,“ec2:CReateKeyPair“],”Resource“:”*“,”Condition“:{”DateGreaterThan“:{”Aws:CurrentTime“:”2020-06-30T23:59:59Z“},”DateLessThanEquals“:{”Aws:CurrentTime“:”2020-04-01T00:00:00Z“}}}]}”这是尝试创建IAM策略时出现的错误:
botocore.errorfactory.MalformedPolicyDocumentException: An error occurred (MalformedPolicyDocument) when calling the CreatePolicy operation: Syntax errors in policy.
整个策略有太多的警告,即使我能够通过控制台创建它。
例如,aws:currentTime应该是如下所示的某种思考:
"DateGreaterThan": {"aws:CurrentTime": "2020-04-01T00:00:00Z"},
"DateLessThan": {"aws:CurrentTime": "2020-06-30T23:59:59Z"}
ec2:instanceType
条件没有指定相应的条件值。
{
"Version": "2012-10-17",
"Statement": [
{
"Sid": "VisualEditor0",
"Effect": "Allow",
"Action": "ec2:RunInstances",
"Resource": [
"arn:aws:ec2:us-east-2::instance/",
"arn:aws:ec2:us-east-2::network-interface/",
"arn:aws:ec2:us-east-2::key-pair/",
"arn:aws:ec2:us-east-2::security-group/",
"arn:aws:ec2:us-east-2::subnet/",
"arn:aws:ec2:us-east-2::volume/",
"arn:aws:ec2:us-east-2::image/ami-"
],
"Condition": {
"ForAllValues:NumericLessThanEquals": {
"ec2:VolumeSize": "20"
},
"ForAllValues:StringEquals": {
"ec2:InstanceType": ""
}
}
},
{
"Sid": "VisualEditor1",
"Effect": "Allow",
"Action": [
"ec2:TerminateInstances",
"ec2:StartInstances",
"ec2:StopInstances"
],
"Resource": "arn:aws:ec2:us-east-2::instance/",
"Condition": {
"ForAllValues:StringEquals": {
"ec2:InstanceType": ""
}
}
},
{
"Sid": "VisualEditor2",
"Effect": "Allow",
"Action": [
"ec2:Describe*",
"ec2:GetConsole*",
"cloudwatch:DescribeAlarms",
"iam:ListInstanceProfiles",
"cloudwatch:GetMetricStatistics",
"ec2:DescribeKeyPairs",
"ec2:CreateKeyPair"
],
"Resource": "*",
"Condition": {
"DateGreaterThan": {
"aws:CurrentTime": "30"
},
"DateLessThanEquals": {
"aws:CurrentTime": "20"
}
}
}
]
}
我对策略变量${aws: username}感到困惑,即它是我在AWS帐户中登录的IAM用户名,还是我在创建实例时手动输入的标记值。 实际上,我想实现ec2实例的唯一所有者应该是执行操作
我知道这可以用EC2s完成,所以我想知道同样的方法是否适用于S3桶,因为我在上面找不到任何文档。谢谢!
我希望设置不同的AWS标识和访问管理(IAM)用户,以便在该IAM用户创建AWS资源时,自动为该资源分配特定的标记。 例如:如果IAM user F创建一个新的EC2实例,该实例将自动标记为user:MrF。是否可以构建一个自定义策略来执行此操作?
我无法找到通过 CLI 创建自定义备份策略的方法 https://docs.microsoft.com/en-us/cli/azure/backup/policy?view=azure-cli-latest 但是,这可以通过REST API调用来完成https://docs.microsoft.com/en-us/azure/backup/backup-azure-arm-userestapi-c
我有一个AWS帐户,其中包含我所有的东西,并想保护它。 我想创建一个包含一些拒绝操作的IAM策略,并将该策略应用于所有现有和未来用户。我该怎么做? 我试图使用IAM组,但是有人可以创建一个没有特定组的用户。此外,我尝试了组织SCP,但它似乎与主帐户不工作。
我想做什么(继续我之前问过的一个问题:如何通过PowerShell中的IAM角色过滤AWS实例,并获取该实例的私有IP地址?)获取具有特定IAM角色的实例的专用ip地址。我有一个完美的代码: 但是,现在我想创建一个IAM策略来限制用户只能获取具有特定IAM角色的实例的信息,而不是在代码中进行筛选。因此,如果他们试图(例如),它应该只返回有关实例的信息,而不是帐户中的所有实例。 这是我的IAM政策,