Upload to repository

Let’s go through the instructions to upload the code to AWS CodeCommit.

  1. In the terminal tab, run this command to create a repository

    aws codecommit create-repository --repository-name api
    

    Copy the value of cloneUrlHttp, you will need it later.

    One of the cool things about CodeCommit is the support for IAM authentication. And if you are running this workshop from a Cloud9 workspace, you can leverage the fact that your terminal is already pre-authenticated with valid AWS credentials.

  2. Configure the git client with username and email, so your commits have an author defined.

    git config --global user.name "First Last"
    git config --global user.email "first.last@example.com"
    
  3. Open the api/.gitgnore file from the file navigation pane. Copy and paste the following line to the end of the file. There is no need to track the .aws-sam/build directory as they are re-generated on every build.

    .aws-sam/build
    
  4. Go back to the Cloud9 terminal tab. Let’s initialise the local repository, add the files, and commit.

    git init -b main
    git add .
    git commit -m "Initial commit"
    
  5. Add your CodeCommit repository URL as a remote on your local git project.

    git remote add origin codecommit://api
    
  6. Now push the code.

    git push -u origin main