@@ -527,7 +527,10 @@ def start_availability_zone_power_interruption_scenario(
527
527
role_arn = response ["Role" ]["Arn" ]
528
528
logger .debug (f"FIS Role created: { role_arn } " )
529
529
530
- target_region , _ = az .rsplit ("-" , 1 )
530
+ a , b , c = az .split ("-" , 2 )
531
+ target_region = f"{ a } -{ b } -{ c [0 ]} "
532
+ logger .debug (f"Target AZ { az } " )
533
+ logger .debug (f"Target region { target_region } " )
531
534
532
535
if create_console_ebsvolume_policy :
533
536
response = iam_client .create_policy (
@@ -560,40 +563,9 @@ def start_availability_zone_power_interruption_scenario(
560
563
)
561
564
562
565
if create_console_ec2_policy :
563
- response = iam_client .create_policy (
564
- PolicyName = f"FIS-Console-EC2-{ suffix } " ,
565
- PolicyDocument = json .dumps (
566
- {
567
- "Version" : "2012-10-17" ,
568
- "Statement" : [
569
- {
570
- "Sid" : "AllowFISExperimentRoleEC2Actions" ,
571
- "Effect" : "Allow" ,
572
- "Action" : [
573
- "ec2:RebootInstances" ,
574
- "ec2:StopInstances" ,
575
- "ec2:StartInstances" ,
576
- "ec2:TerminateInstances" ,
577
- ],
578
- "Resource" : f"arn:aws:ec2:{ target_region } :{ account_id } :instance/*" ,
579
- },
580
- {
581
- "Sid" : "AllowFISExperimentRoleSpotInstanceActions" ,
582
- "Effect" : "Allow" ,
583
- "Action" : ["ec2:SendSpotInstanceInterruptions" ],
584
- "Resource" : f"arn:aws:ec2:{ target_region } :{ account_id } :instance/*" ,
585
- },
586
- ],
587
- }
588
- ),
589
- Tags = tags_as_kv ,
590
- )
591
-
592
- policy_arn = response ["Policy" ]["Arn" ]
593
- logger .debug (f"Role policy created: { policy_arn } " )
594
-
595
566
response = iam_client .attach_role_policy (
596
- RoleName = role_name , PolicyArn = policy_arn
567
+ RoleName = role_name ,
568
+ PolicyArn = "arn:aws:iam::aws:policy/service-role/AWSFaultInjectionSimulatorEC2Access" ,
597
569
)
598
570
599
571
response = iam_client .create_policy (
@@ -673,88 +645,9 @@ def start_availability_zone_power_interruption_scenario(
673
645
)
674
646
675
647
if create_console_network_policy :
676
- response = iam_client .create_policy (
677
- PolicyName = f"FIS-Console-Network-{ suffix } " ,
678
- PolicyDocument = json .dumps (
679
- {
680
- "Version" : "2012-10-17" ,
681
- "Statement" : [
682
- {
683
- "Effect" : "Allow" ,
684
- "Action" : "ec2:CreateTags" ,
685
- "Resource" : "arn:aws:ec2:*:*:network-acl/*" ,
686
- "Condition" : {
687
- "StringEquals" : {
688
- "ec2:CreateAction" : "CreateNetworkAcl" ,
689
- "aws:RequestTag/managedByFIS" : "true" ,
690
- }
691
- },
692
- },
693
- {
694
- "Effect" : "Allow" ,
695
- "Action" : "ec2:CreateNetworkAcl" ,
696
- "Resource" : "arn:aws:ec2:*:*:network-acl/*" ,
697
- "Condition" : {
698
- "StringEquals" : {
699
- "aws:RequestTag/managedByFIS" : "true"
700
- }
701
- },
702
- },
703
- {
704
- "Effect" : "Allow" ,
705
- "Action" : [
706
- "ec2:CreateNetworkAclEntry" ,
707
- "ec2:DeleteNetworkAcl" ,
708
- ],
709
- "Resource" : [
710
- "arn:aws:ec2:*:*:network-acl/*" ,
711
- "arn:aws:ec2:*:*:vpc/*" ,
712
- ],
713
- "Condition" : {
714
- "StringEquals" : {
715
- "ec2:ResourceTag/managedByFIS" : "true"
716
- }
717
- },
718
- },
719
- {
720
- "Effect" : "Allow" ,
721
- "Action" : "ec2:CreateNetworkAcl" ,
722
- "Resource" : "arn:aws:ec2:*:*:vpc/*" ,
723
- },
724
- {
725
- "Effect" : "Allow" ,
726
- "Action" : [
727
- "ec2:DescribeVpcs" ,
728
- "ec2:DescribeManagedPrefixLists" ,
729
- "ec2:DescribeSubnets" ,
730
- "ec2:DescribeNetworkAcls" ,
731
- ],
732
- "Resource" : "*" ,
733
- },
734
- {
735
- "Effect" : "Allow" ,
736
- "Action" : "ec2:ReplaceNetworkAclAssociation" ,
737
- "Resource" : [
738
- "arn:aws:ec2:*:*:subnet/*" ,
739
- "arn:aws:ec2:*:*:network-acl/*" ,
740
- ],
741
- },
742
- {
743
- "Effect" : "Allow" ,
744
- "Action" : "ec2:GetManagedPrefixListEntries" ,
745
- "Resource" : "arn:aws:ec2:*:*:prefix-list/*" ,
746
- },
747
- ],
748
- }
749
- ),
750
- Tags = tags_as_kv ,
751
- )
752
-
753
- policy_arn = response ["Policy" ]["Arn" ]
754
- logger .debug (f"Role policy created: { policy_arn } " )
755
-
756
648
response = iam_client .attach_role_policy (
757
- RoleName = role_name , PolicyArn = policy_arn
649
+ RoleName = role_name ,
650
+ PolicyArn = "arn:aws:iam::aws:policy/service-role/AWSFaultInjectionSimulatorNetworkAccess" ,
758
651
)
759
652
760
653
if enable_rds_policy :
@@ -884,7 +777,11 @@ def restore_availability_zone_power_after_interruption(
884
777
for policy in policies :
885
778
policy_name = policy ["PolicyName" ]
886
779
# don't delete managed policies
887
- if policy_name in ["AWSFaultInjectionSimulatorRDSAccess" ]:
780
+ if policy_name in [
781
+ "AWSFaultInjectionSimulatorRDSAccess" ,
782
+ "AWSFaultInjectionSimulatorNetworkAccess" ,
783
+ "AWSFaultInjectionSimulatorEC2Access" ,
784
+ ]:
888
785
continue
889
786
890
787
logger .debug (f"Deleting policy { policy_name } " )
0 commit comments