title: How can codecommit files be uploaded to s3 automatically?
body: <p>The below code gives me only bytes which are changed but not the entire file. coming to s3 part the zip file is creating but with size as zero bytes whereas actual size will be some 70-80 bytes. I need a method where all files in repository will be pushed to s3 when a push event occurs.
  at least tell me how to get all files from the repository when push even occurs.</p>
  
  <p>Thanks in advance!</p>
  
  <pre><code>import boto3
  import pathlib
  import tarfile
  import io
  import sys
  import os
  
  
  codecommit = boto3.client("codecommit")
  
  def get_differences(repository_name, branch="master"):
      response = codecommit.get_differences(
          repositoryName=repository_name,
          afterCommitSpecifier='master',
      )
      differences = []
      while "nextToken" in response:
          response = codecommit.get_differences(
              repositoryName=repository_name,
              afterCommitSpecifier='master',
              nextToken=response["nextToken"]
          )
          differences += response.get("differences", [])
      else:
          differences += response["differences"]
      return differences
  
  def main(event,context):
      repository_name = event['Records'][0]['eventSourceARN'].split(':')[5]
      repository_path = pathlib.Path(repository_name)
      buf = io.BytesIO()
      with tarfile.open(None, "w:gz", fileobj=buf) as tar:
      for difference in get_differences(repository_name):
          blobid = difference["afterBlob"]["blobId"]
          path = difference["afterBlob"]["path"]
          mode = difference["afterBlob"]["mode"] # noqa
          blob = codecommit.get_blob(
              repositoryName=repository_name, blobId=blobid)
          tarinfo = tarfile.TarInfo(str(repository_path / path))
          tarinfo.size = len(blob["content"])
          tar.addfile(tarinfo, io.BytesIO(blob["content"]))
          tarobject = buf.getvalue()
  # save to s3
  s3 = boto3.client('s3')
  s3.filename = str(repository_name)
  s3.bucket = 'csharp-codes-codecommit' 
  response = s3.put_object(Bucket=s3.bucket,Key= '/tmp/'+str(repository_path))
  </code></pre>