如何使用codedeploy在ASG下自动将代码部署到新创建的EC2实例?

时间:2017-07-18 21:26:49

标签: amazon-web-services autoscaling aws-code-deploy

我在ASG下有2个EC2实例。我在codeDeploy中创建了Application1,其DeploymentGroup1设置为使用Autoscaling。

我面临的问题是,在配置新的EC2实例时,codedeploy不会创建新的部署,代码也不会被推送到实例。它看起来似乎没有日志甚至可以看到正在发生的事情。

当我列出我的Autoscaling Group的钩子时,我确实看到了它们:

$ aws autoscaling describe-lifecycle-hooks --auto-scaling-group-name SAND-web-ASG 
{
    "LifecycleHooks": [
        {
            "GlobalTimeout": 60000,
            "HeartbeatTimeout": 600,
            "AutoScalingGroupName": "SAND-web-ASG",
            "LifecycleHookName": "CodeDeploy-managed-automatic-launch-deployment-hook-DeployToNewEC2underASG-...",
            "NotificationMetadata": "....",
            "DefaultResult": "ABANDON",
            "NotificationTargetARN": "arn:aws:sqs:us-west-1:blabla:blahh-us-west-1-prod-default-autoscaling-lifecycle-hook",
            "LifecycleTransition": "autoscaling:EC2_INSTANCE_LAUNCHING"
        }
    ]
}

这里有什么遗漏或错误吗?这些不是自定义的,它们是由codedeploy创建的。

我关注guide to setup codedeploy with ASG并且创建了所有内容,但由于某些原因,在创建新实例时,codedeploy并没有创建新的部署..而且我有点迷失了原因..

我的服务角色有2个IAM政策:

1 - 默认来自amazon AWSCodedeployRole

2 - 具有以下权限的codePipelinePolicy(自定义):

{
  "Version": "2012-10-17",
  "Statement": [
    {
      "Effect": "Allow",
      "Action": [
        "autoscaling:CompleteLifecycleAction",
        "autoscaling:DeleteLifecycleHook",
        "autoscaling:DescribeAutoScalingGroups",
        "autoscaling:DescribeLifecycleHooks",
        "autoscaling:PutLifecycleHook",
        "autoscaling:RecordLifecycleActionHeartbeat",
        "autoscaling:CreateAutoScalingGroup",
        "autoscaling:UpdateAutoScalingGroup",
        "autoscaling:EnableMetricsCollection",
        "autoscaling:DescribeAutoScalingGroups",
        "autoscaling:DescribePolicies",
        "autoscaling:DescribeScheduledActions",
        "autoscaling:DescribeNotificationConfigurations",
        "autoscaling:DescribeLifecycleHooks",
        "autoscaling:SuspendProcesses",
        "autoscaling:ResumeProcesses",
        "autoscaling:AttachLoadBalancers",
        "autoscaling:PutScalingPolicy",
        "autoscaling:PutScheduledUpdateGroupAction",
        "autoscaling:PutNotificationConfiguration",
        "autoscaling:PutLifecycleHook",
        "autoscaling:DescribeScalingActivities",
        "autoscaling:DeleteAutoScalingGroup",
        "ec2:DescribeInstances",
        "ec2:DescribeInstanceStatus",
        "ec2:TerminateInstances",
        "tag:GetTags",
        "tag:GetResources",
        "sns:Publish",
        "cloudwatch:DescribeAlarms",
        "elasticloadbalancing:DescribeLoadBalancers",
        "elasticloadbalancing:DescribeInstanceHealth",
        "elasticloadbalancing:RegisterInstancesWithLoadBalancer",
        "elasticloadbalancing:DeregisterInstancesFromLoadBalancer"
      ],
      "Resource": "*"
    }
  ]
}

我是否在这里遗漏了某些东西,或者可能有些错误(愚蠢的错误),我没有看到?

任何建议都非常感谢。 谢谢, 欧内斯特

1 个答案:

答案 0 :(得分:0)

从您的描述中,我没有看到您提到已成功部署到您的应用程序。在扩展期间,CodeDeploy将尝试部署应用程序的目标修订版,但如果没有找到,则它根本不会发布部署,这将导致您看到的问题。您应该执行部署以更新应用程序的目标修订版,然后尝试按比例放大,看看是否能解决问题。