2

I am having trouble with AWS Codepipeline, rather than deploying the entire Codecommit repo to an S3 bucket, I would like Codepipeline to only deploy a single file that was updated. The same question is asked here: Codepipeline: Deploy only specific files to s3 but I do not want any specific file. Any file whether its HTML or Css, only the one that is updated should be deployed to S3

I am using AWS CodeBuild, my deployment yaml file is this:

version: 0.2

phases:
  install:
    commands:
      - echo Entered the install phase...
      - apt-get update -y
build:
  commands:
    - echo Building...
artifacts:
  files:
    - index.html
  discard-paths: yes
  secondary-artifacts:
    artifact1:
      files:
        - index.html

Now in the above code instead of index.html in artifacts what should I write so that even if any other file is changed or updated, then only that single file should be updated in S3 bucket.

1 Answers1

0

Unfortunately, there is no build in functionality for this in CodeBuild.This means that you would have to program it yourself in your CodeBuild procedure.

A possible way could be by listing files in your CodeCommit repository which were changed in the last commit. You can do this using git's functionality.

Marcin
  • 215,873
  • 14
  • 235
  • 294
  • You means to apply git’s functionality and nothing to deal with code build artifacts? If yes, I also tried to look online on basis of this but in vain. Can you tell me where to add this functionality and how. Also can’t we do something with environment variables? – Hetul Sheth May 02 '20 at 03:14
  • @HetulSheth My point is that there is no such functionality in CodeBuild. You have to implement such functionality yourself. Using git, as you use CodeCommit, it can be possible to get a list of files which changed between two recent commits or in last commit. One example of this is shown [here](https://stackoverflow.com/questions/1552340/how-to-list-only-the-file-names-that-changed-between-two-commits). Maybe other way would involve doing something with "environment variables", though I don't know how would env variables be used in CodeCommit for that. – Marcin May 02 '20 at 03:24
  • @HetulSheth As I think about this, CodeBuild also supports caching. So maybe you could use that. Have previous version cached, and when the new version is to be deployed, can compare the two and choose the changed files only. Or directly compare the files with those already hosted on s3, and identified those changed. – Marcin May 02 '20 at 04:01