Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Unable to download AWS CodeDeploy Agent Install file

I am trying to download AWS Codedeploy Agent file in my Amazon Linux. I followed instructions as mentioned in http://docs.aws.amazon.com/codedeploy/latest/userguide/how-to-run-agent.html, for Amazon Linux, have created appropriate instance profile, service role etc. Everything is latest (Amazon Linux, CLI Packages, it is a brand new instance and I have tried this with at least 3 more brand new instances with same result). All instances have full outbound internet access.

But following statement for downloading install from S3 always fails,

aws s3 cp s3://aws-codedeploy-us-east-1/latest/install . --region us-east-1

With Error, A client error (403) occurred when calling the HeadObject operation: Forbidden Completed 1 part(s) with ... file(s) remaining

Can anyone help me with this error?

like image 548
arva Avatar asked Nov 20 '14 05:11

arva


2 Answers

I figured out the problem, According to Codedeploy documentation for IAM Instance profile

http://docs.aws.amazon.com/codedeploy/latest/userguide/how-to-create-iam-instance-profile.html

following permissions needs to be given to your IAM instance profile.

{
  "Version": "2012-10-17",
  "Statement": [
    {
      "Action": [
        "s3:Get*",
        "s3:List*"
      ],
      "Effect": "Allow",
      "Resource": "*"
    }
  ]
}

But I limited the resource to my code bucket since I don't want my instances to access other buckets directly. But turns out I also need to give additional permission for aws-codedeploy-us-east-1/* s3 resource for being able to download the agent. This is not very clear in the document for setting up IAM instance profile for Codedeploy.

like image 58
arva Avatar answered Sep 28 '22 20:09

arva


More restrictive policy that works:

{
    "Version": "2012-10-17",
    "Statement": [
        {
            "Effect": "Allow",
            "Action": [
                "s3:Get*",
                "s3:List*"
            ],
            "Resource": [
                "arn:aws:s3:::aws-codedeploy-us-east-1/*",
                "arn:aws:s3:::aws-codedeploy-us-west-1/*",
                "arn:aws:s3:::aws-codedeploy-us-west-2/*",
                "arn:aws:s3:::aws-codedeploy-ap-south-1/*",
                "arn:aws:s3:::aws-codedeploy-ap-northeast-2/*",
                "arn:aws:s3:::aws-codedeploy-ap-southeast-1/*",
                "arn:aws:s3:::aws-codedeploy-ap-southeast-2/*",
                "arn:aws:s3:::aws-codedeploy-ap-northeast-1/*",
                "arn:aws:s3:::aws-codedeploy-eu-central-1/*",
                "arn:aws:s3:::aws-codedeploy-eu-west-1/*",
                "arn:aws:s3:::aws-codedeploy-sa-east-1/*"
            ]
        }
    ]
}
like image 30
Maciej Mucha Avatar answered Sep 28 '22 18:09

Maciej Mucha