Skip to content

Commit e32d4a2

Browse files
authored
Merge pull request #7 from aws-samples/commit_hash
Added commit hash to S3 object
2 parents fa4bdde + 6336914 commit e32d4a2

4 files changed

Lines changed: 13 additions & 6 deletions

File tree

buildspec.yml

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,8 @@ phases:
88
- env
99
- git clone -b $REFERENCE_NAME codecommit::$REPO_REGION://$REPOSITORY_NAME
1010
- dt=$(date '+%d-%m-%Y-%H:%M:%S');
11-
- echo "$dt"
12-
- zip -yr $dt-$REPOSITORY_NAME-backup.zip ./
13-
- aws s3 cp $dt-$REPOSITORY_NAME-backup.zip s3://$BUCKET/$REPOSITORY_NAME/
11+
- echo "$dt"
12+
- SHORT_COMMIT_ID=$(echo "$COMMIT_ID" | cut -c1-8)
13+
- object=$dt-$REPOSITORY_NAME-$SHORT_COMMIT_ID
14+
- zip -yr $object.zip ./
15+
- aws s3 cp $object.zip s3://$BUCKET/$REPOSITORY_NAME/

cloudwatch.tf

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -41,6 +41,7 @@ resource "aws_cloudwatch_event_target" "this" {
4141
repositoryName = "$.detail.repositoryName",
4242
account = "$.account",
4343
referenceName = "$.detail.referenceName",
44+
commitId = "$.detail.commitId",
4445
}
4546
input_template = <<EOF
4647
{
@@ -64,6 +65,10 @@ resource "aws_cloudwatch_event_target" "this" {
6465
{
6566
"name": "ACCOUNT_ID",
6667
"value": <account>
68+
},
69+
{
70+
"name": "COMMIT_ID",
71+
"value": <commitId>
6772
}
6873
]
6974
}

codebuild.tf

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -81,7 +81,7 @@ data "aws_iam_policy_document" "codebuild" {
8181
]
8282

8383
resources = [
84-
"${aws_s3_bucket.this.arn}",
84+
aws_s3_bucket.this.arn,
8585
"${aws_s3_bucket.this.arn}/*"
8686
]
8787
}

s3.tf

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -42,8 +42,8 @@ data "aws_iam_policy_document" "this" {
4242
]
4343

4444
resources = [
45-
"${aws_s3_bucket.this.arn}/*",
46-
"${aws_s3_bucket.this.arn}"
45+
aws_s3_bucket.this.arn,
46+
"${aws_s3_bucket.this.arn}/*"
4747
]
4848

4949
condition {

0 commit comments

Comments
 (0)