信任关系错误AssumeRole策略可能仅指定STS AssumeRole操作

时间:2019-12-18 08:07:32

标签: amazon-web-services amazon-ec2 amazon-iam

我正在尝试添加信任关系,以允许Codedeploy发挥作用

我有以下json

{
  "Version": "2012-10-17",
  "Statement": [
    {
      "Effect": "Allow",
      "Principal": {
        "Service": ["ec2.amazonaws.com", "codedeploy.amazonaws.com"]
      },
      "Action": ["sts:AssumeRole",
                "codedeploy:GetApplication",
                "codedeploy:GetDeploymentGroup",
                "codedeploy:CreateDeployment",
                "codedeploy:GetDeployment"      
      ]
    }
  ]
}

我一直收到以下错误

enter image description here

1 个答案:

答案 0 :(得分:1)

您在策略中混用了两个不同的概念:信任关系和IAM操作。

您需要有两种不同的策略,一种针对IAM角色,例如:

<?php
$curDateTime->setTimezone(new \DateTimeZone("UTC"));
$curStrTime = strtotime($curDateTime->format('Y-m-d H:i:s'));
// to get the time less than one hour
// Cron job will run for each one hour
$minusOneDateTime = new \DateTime('now -1 hour');
$minusOneDateTime->setTimezone(new \DateTimeZone("UTC"));
$minusOneStrTime = strtotime($minusOneDateTime->format('Y-m-d H:i:s'));
//alert days
$alertDays = [1,2,4,7,14,21,28];
$companies = $em->getRepository('AppBundle:BpUser')->getunResponsiveCompanyList($statusArray, $maxDays);
foreach ($companies as $companyArray) {
    $company =  $em->getRepository('AppBundle:BpUser')->findOneById($companyArray[0]['id']);
    if ($company instanceof \AppBundle\Entity\BpUser) {
        $damage = $em->getRepository('AppBundle:BpDamage')->findOneById($companyArray['damageId']);
        $this->sendEmail($damage, $company);
        $dateCompare = $companyArray['compareTime'];
        $dateCompare->setTimezone(new \DateTimeZone("UTC"));
        // To create the remainder times
        foreach($alertDays as $alertDay) {
            $alertDate =  strtotime($stop_date . "+$alertDay day");
             // Check the remainder time
            if($alertDate >= strtotime($minusOneStrTime) && $alertDate <= strtotime($curStrTime)) {
                $company =  $em->getRepository('AppBundle:MyUser')->findOneById($companyArray[0]['id']);
                if ($company instanceof \AppBundle\Entity\MyUser) {
                    $damage = $em->getRepository('AppBundle:MyDamage')->findOneById($companyArray['damageId']);
                    $this->sendEmail($damage, $company); //add data to mail queue
                }
            }
        }
    }
?>

和其他有关IAM政策的信息:

<script>
  $( function() {
    $( "#selectable" ).selectable({
      stop: function() {
        var result = $( "#select-result" ).empty();
        $( ".ui-selected", this ).each(function() {
          var index = $( "#selectable li" ).index( this );
          result.append( " #" + ( index + 1 ) );
        });
      }
    });
  } );
  </script>