Skip to content

Commit 7eba4d7

Browse files
authored
Merge pull request awsdocs#69 from anibalsanchez/master
Sample policy for CodeBuildAccess, with both cases
2 parents 1de27d0 + b59f342 commit 7eba4d7

File tree

1 file changed

+42
-30
lines changed

1 file changed

+42
-30
lines changed

doc_source/sample-ecr.md

Lines changed: 42 additions & 30 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22

33
This sample uses a Docker image in an Amazon Elastic Container Registry \(Amazon ECR\) image repository to build a sample Go project\.
44

5-
**Important**
5+
**Important**
66
Running this sample might result in charges to your AWS account\. These include possible charges for AWS CodeBuild and for AWS resources and actions related to Amazon S3, AWS KMS, CloudWatch Logs, and Amazon ECR\. For more information, see [CodeBuild pricing](http://aws.amazon.com/codebuild/pricing), [Amazon S3 pricing](http://aws.amazon.com/s3/pricing), [AWS Key Management Service pricing](http://aws.amazon.com/kms/pricing), [Amazon CloudWatch pricing](http://aws.amazon.com/cloudwatch/pricing), and [Amazon Elastic Container Registry pricing](http://aws.amazon.com/ecr/pricing)\.
77

88
## Running the sample<a name="sample-ecr-running"></a>
@@ -11,11 +11,11 @@ Running this sample might result in charges to your AWS account\. These include
1111

1212
1. To create and push the Docker image to your image repository in Amazon ECR, complete the steps in the "Running the sample" section of the [Docker sample](sample-docker.md)\.
1313

14-
1. Create a Go project:
14+
1. Create a Go project:
1515

16-
1. Create the files as described in the [Go project structure](#ecr-sample-go-project-file-structure) and [Go project files](#sample-ecr-go-project-files) sections of this topic, and then upload them to an S3 input bucket or an AWS CodeCommit, GitHub, or Bitbucket repository\.
17-
**Important**
18-
Do not upload `(root directory name)`, just the files inside of `(root directory name)`\.
16+
1. Create the files as described in the [Go project structure](#ecr-sample-go-project-file-structure) and [Go project files](#sample-ecr-go-project-files) sections of this topic, and then upload them to an S3 input bucket or an AWS CodeCommit, GitHub, or Bitbucket repository\.
17+
**Important**
18+
Do not upload `(root directory name)`, just the files inside of `(root directory name)`\.
1919
If you are using an S3 input bucket, be sure to create a ZIP file that contains the files, and then upload it to the input bucket\. Do not add `(root directory name)` to the ZIP file, just the files inside of `(root directory name)`\.
2020

2121
1. Create a build project, run the build, and view related build information by following the steps in [Run AWS CodeBuild directly](how-to-run.md)\.
@@ -47,11 +47,11 @@ If you are using an S3 input bucket, be sure to create a ZIP file that contains
4747
4848
1. To get the build output artifact, open your S3 output bucket\.
4949
50-
1. Download the `GoOutputArtifact.zip` file to your local computer or instance, and then extract the contents of the file\. In the extracted contents, get the `hello` file\.
50+
1. Download the `GoOutputArtifact.zip` file to your local computer or instance, and then extract the contents of the file\. In the extracted contents, get the `hello` file\.
5151
52-
1. If one of the following is true, you must add permissions to your image repository in Amazon ECR so that AWS CodeBuild can pull its Docker image into the build environment\.
53-
+ Your project uses CodeBuild credentials to pull Amazon ECR images\. This is denoted by a value of `CODEBUILD` in the `imagePullCredentialsType` attribute of your `ProjectEnvironment`\.
54-
+ Your project uses a cross\-account Amazon ECR image\. In this case, your project must use its service role to pull Amazon ECR images\. To enable this behavior, set the `imagePullCredentialsType` attribute of your `ProjectEnvironment` to `SERVICE_ROLE`\.
52+
1. If one of the following is true, you must add permissions to your image repository in Amazon ECR so that AWS CodeBuild can pull its Docker image into the build environment\.
53+
+ Your project uses CodeBuild credentials to pull Amazon ECR images\. This is denoted by a value of `CODEBUILD` in the `imagePullCredentialsType` attribute of your `ProjectEnvironment`\.
54+
+ Your project uses a cross\-account Amazon ECR image\. In this case, your project must use its service role to pull Amazon ECR images\. To enable this behavior, set the `imagePullCredentialsType` attribute of your `ProjectEnvironment` to `SERVICE_ROLE`\.
5555
5656
1. Open the Amazon ECR console at [https://console\.aws\.amazon\.com/ecr/](https://console.aws.amazon.com/ecr/)\.
5757
@@ -64,7 +64,7 @@ If you are using an S3 input bucket, be sure to create a ZIP file that contains
6464
1. For **Effect**, leave **Allow** selected\. This indicates that you want to allow access to another AWS account\.
6565
6666
1. For **Principal**, do one of the following:
67-
+ If your project uses CodeBuild credentials to pull an Amazon ECR image, in **Service principal**, enter **codebuild\.amazonaws\.com**\.
67+
+ If your project uses CodeBuild credentials to pull an Amazon ECR image, in **Service principal**, enter **codebuild\.amazonaws\.com**\.
6868
+ If your project uses a cross\-account Amazon ECR image, for **AWS account IDs**, enter IDs of the AWS accounts that you want to give access\.
6969
7070
1. Skip the **All IAM entities** list\.
@@ -81,25 +81,37 @@ If you are using an S3 input bucket, be sure to create a ZIP file that contains
8181
8282
```
8383
{
84-
"Version": "2012-10-17",
85-
"Statement": [
86-
{
87-
"Sid": "CodeBuildAccess",
88-
"Effect": "Allow",
89-
"Principal": {
90-
"AWS": "arn:aws:iam::AWS-account-ID:root"
84+
"Version":"2012-10-17",
85+
"Statement":[
86+
{
87+
"Sid":"CodeBuildAccessPrincipal",
88+
"Effect":"Allow",
89+
"Principal":{
90+
"Service":"codebuild.amazonaws.com"
91+
},
92+
"Action":[
93+
"ecr:BatchCheckLayerAvailability",
94+
"ecr:BatchGetImage",
95+
"ecr:GetDownloadUrlForLayer"
96+
]
9197
},
92-
"Action": [
93-
"ecr:GetDownloadUrlForLayer",
94-
"ecr:BatchGetImage",
95-
"ecr:BatchCheckLayerAvailability"
96-
]
97-
}
98+
{
99+
"Sid":"CodeBuildAccessCrossaccount",
100+
"Effect":"Allow",
101+
"Principal":{
102+
"AWS":"arn:aws:iam::AWS-account-ID:root"
103+
},
104+
"Action":[
105+
"ecr:GetDownloadUrlForLayer",
106+
"ecr:BatchGetImage",
107+
"ecr:BatchCheckLayerAvailability"
108+
]
109+
}
98110
]
99111
}
100112
```
101113
102-
1. Create a build project, run the build, and view build information by following the steps in [Run AWS CodeBuild directly](how-to-run.md)\.
114+
2. Create a build project, run the build, and view build information by following the steps in [Run AWS CodeBuild directly](how-to-run.md)\.
103115
104116
If you use the AWS CLI to create the build project, the JSON\-formatted input to the `create-project` command might look similar to this\. \(Replace the placeholders with your own values\.\)
105117
@@ -126,9 +138,9 @@ If you are using an S3 input bucket, be sure to create a ZIP file that contains
126138
}
127139
```
128140
129-
1. To get the build output artifact, open your S3 output bucket\.
141+
3. To get the build output artifact, open your S3 output bucket\.
130142
131-
1. Download the `GoOutputArtifact.zip` file to your local computer or instance, and then extract the contents of the `GoOutputArtifact.zip` file\. In the extracted contents, get the `hello` file\.
143+
4. Download the `GoOutputArtifact.zip` file to your local computer or instance, and then extract the contents of the `GoOutputArtifact.zip` file\. In the extracted contents, get the `hello` file\.
132144
133145
## Go project structure<a name="ecr-sample-go-project-file-structure"></a>
134146
@@ -150,14 +162,14 @@ This sample uses these files\.
150162
version: 0.2
151163

152164
phases:
153-
install:
154-
runtime-versions:
155-
golang: 1.13
165+
install:
166+
runtime-versions:
167+
golang: 1.13
156168
build:
157169
commands:
158170
- echo Build started on `date`
159171
- echo Compiling the Go code...
160-
- go build hello.go
172+
- go build hello.go
161173
post_build:
162174
commands:
163175
- echo Build completed on `date`

0 commit comments

Comments
 (0)