Push the code

Ignore the build artifacts

Copy and paste the following lines at the end of the sam-app/.gitgnore file. There is no need to track the .aws-sam directory or the packaged.yaml under version control as they are re-generated on every build.

.aws-sam/
packaged.yaml

Open the .gitignore file and paste the two lines described above.

GitIgnore

From the root directory of your sam-app project, run the following commands:

The last command changes the default branch from master to main for this repository. If your default branch is already configured as main you can skip that command.

cd ~/environment/sam-app
git init
git add .
git commit -m "Initial commit"
git branch -m master main

Example: GitCommit

Push the code

Add your CodeCommit repository URL as a remote on your local git project.

git remote add origin codecommit://sam-app

If you typed the origin url incorrectly, you can remove it by running: git remote rm origin.

Now, push the code:

git push -u origin main

Example:

GitPush

Verify in CodeCommit

Navigate to the AWS CodeCommit console, find your sam-app repository and click on it to view its contents. Make sure your code is there. You should see a screen like the following:

VerifyCodeCommit