Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
52 changes: 52 additions & 0 deletions tuts/096-aws-codecommit-gs/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,52 @@
# CodeCommit: Create a repository and manage code

Create a CodeCommit repository, add files, branch, compare changes, and retrieve metadata using the AWS CLI.

## Source

https://docs.aws.amazon.com/codecommit/latest/userguide/getting-started-cc.html

## Use case

- ID: codecommit/getting-started
- Phase: create
- Complexity: beginner
- Core actions: codecommit:CreateRepository, codecommit:PutFile, codecommit:CreateBranch

## What it does

1. Creates a CodeCommit repository
2. Adds a file using fileb://
3. Retrieves the file metadata
4. Creates a feature branch
5. Adds a file to the feature branch
6. Compares branches with get-differences
7. Gets repository metadata

## Running

```bash
bash aws-codecommit-gs.sh
```

## Resources created

- CodeCommit repository

No persistent resources remain after cleanup. The script prompts you to delete the repository when it finishes.

## Estimated time

- Run: ~11 seconds

## Cost

CodeCommit is free for up to 5 active users per month (unlimited repositories). No charges for this tutorial under the free tier.

## Related docs

- [Getting started with CodeCommit](https://docs.aws.amazon.com/codecommit/latest/userguide/getting-started-cc.html)
- [put-file CLI reference](https://docs.aws.amazon.com/cli/latest/reference/codecommit/put-file.html)
- [Working with branches](https://docs.aws.amazon.com/codecommit/latest/userguide/how-to-create-branch.html)
- [CodeCommit quotas](https://docs.aws.amazon.com/codecommit/latest/userguide/limits.html)
- [CodeCommit pricing](https://aws.amazon.com/codecommit/pricing/)
8 changes: 8 additions & 0 deletions tuts/096-aws-codecommit-gs/REVISION-HISTORY.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
# Revision History: 096-aws-codecommit-gs

## Shell (CLI script)

### 2026-04-14 v1 published
- Type: functional
- Initial version

108 changes: 108 additions & 0 deletions tuts/096-aws-codecommit-gs/aws-codecommit-gs.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,108 @@
# Create a CodeCommit repository and manage code

This tutorial shows you how to create a CodeCommit repository, add files, create a branch, compare changes between branches, and retrieve repository metadata using the AWS CLI.

## Prerequisites

- AWS CLI configured with credentials and a default region
- Permissions for `codecommit:CreateRepository`, `codecommit:PutFile`, `codecommit:GetFile`, `codecommit:CreateBranch`, `codecommit:ListBranches`, `codecommit:GetDifferences`, `codecommit:GetRepository`, `codecommit:DeleteRepository`

## Step 1: Create a repository

```bash
aws codecommit create-repository --repository-name "$REPO_NAME" \
--repository-description "Tutorial repository" \
--query 'repositoryMetadata.{Name:repositoryName,Id:repositoryId}' --output table
```

CodeCommit returns the repository metadata including the name and unique ID.

## Step 2: Add a file

Write a file locally and upload it with `put-file`. Use `fileb://` to pass the file content as raw bytes:

```bash
echo -e "# Tutorial Repository\n\nThis is a sample file." > "$WORK_DIR/README.md"
COMMIT_ID=$(aws codecommit put-file \
--repository-name "$REPO_NAME" \
--branch-name main \
--file-content "fileb://$WORK_DIR/README.md" \
--file-path README.md \
--commit-message "Initial commit" \
--name "Tutorial User" \
--email "tutorial@example.com" \
--query 'commitId' --output text)
```

The `fileb://` prefix tells the CLI to read the file as raw binary. This creates the `main` branch with the first commit.

## Step 3: Get the file

Retrieve file metadata from the repository:

```bash
aws codecommit get-file --repository-name "$REPO_NAME" \
--file-path README.md \
--query '{Path:filePath,Size:fileSize,CommitId:commitId}' --output table
```

## Step 4: Create a branch

Create a branch from the current commit and list all branches:

```bash
aws codecommit create-branch --repository-name "$REPO_NAME" \
--branch-name feature-branch --commit-id "$COMMIT_ID"
aws codecommit list-branches --repository-name "$REPO_NAME" \
--query 'branches' --output table
```

## Step 5: Add a file to the branch

Add a new file to the feature branch. Pass `--parent-commit-id` to build on the branch tip:

```bash
echo "console.log('Hello from CodeCommit');" > "$WORK_DIR/index.js"
aws codecommit put-file \
--repository-name "$REPO_NAME" \
--branch-name feature-branch \
--file-content "fileb://$WORK_DIR/index.js" \
--file-path src/index.js \
--commit-message "Add source file" \
--parent-commit-id "$COMMIT_ID" \
--query 'commitId' --output text
```

## Step 6: Compare branches

Use `get-differences` to see what changed between `main` and `feature-branch`:

```bash
aws codecommit get-differences \
--repository-name "$REPO_NAME" \
--before-commit-specifier main \
--after-commit-specifier feature-branch \
--query 'differences[].{Path:afterBlob.path,Type:changeType}' --output table
```

## Step 7: Get repository metadata

```bash
aws codecommit get-repository --repository-name "$REPO_NAME" \
--query 'repositoryMetadata.{Name:repositoryName,DefaultBranch:defaultBranch,Created:creationDate}' \
--output table
```

## Cleanup

Delete the repository. This removes all branches, files, and commit history:

```bash
aws codecommit delete-repository --repository-name "$REPO_NAME"
```

The script automates all steps including cleanup:

```bash
bash aws-codecommit-gs.sh
```
100 changes: 100 additions & 0 deletions tuts/096-aws-codecommit-gs/aws-codecommit-gs.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,100 @@
#!/bin/bash
# Tutorial: Create a CodeCommit repository and manage code
# Source: https://docs.aws.amazon.com/codecommit/latest/userguide/getting-started-cc.html

WORK_DIR=$(mktemp -d)
LOG_FILE="$WORK_DIR/codecommit-$(date +%Y%m%d-%H%M%S).log"
exec > >(tee -a "$LOG_FILE") 2>&1

REGION=${AWS_DEFAULT_REGION:-${AWS_REGION:-$(aws configure get region 2>/dev/null)}}
if [ -z "$REGION" ]; then
echo "ERROR: No AWS region configured. Set one with: export AWS_DEFAULT_REGION=us-east-1"
exit 1
fi
export AWS_DEFAULT_REGION="$REGION"
echo "Region: $REGION"

RANDOM_ID=$(cat /dev/urandom | tr -dc 'a-z0-9' | fold -w 8 | head -n 1)
REPO_NAME="tutorial-repo-${RANDOM_ID}"

handle_error() { echo "ERROR on line $1"; trap - ERR; cleanup; exit 1; }
trap 'handle_error $LINENO' ERR

cleanup() {
echo ""
echo "Cleaning up resources..."
aws codecommit delete-repository --repository-name "$REPO_NAME" > /dev/null 2>&1 && \
echo " Deleted repository $REPO_NAME"
rm -rf "$WORK_DIR"
echo "Cleanup complete."
}

# Step 1: Create a repository
echo "Step 1: Creating repository: $REPO_NAME"
aws codecommit create-repository --repository-name "$REPO_NAME" \
--repository-description "Tutorial repository" \
--query 'repositoryMetadata.{Name:repositoryName,Id:repositoryId}' --output table

# Step 2: Add a file
echo "Step 2: Adding a file to the repository"
echo -e "# Tutorial Repository\n\nThis is a sample file created by the CodeCommit tutorial." > "$WORK_DIR/README.md"
COMMIT_ID=$(aws codecommit put-file \
--repository-name "$REPO_NAME" \
--branch-name main \
--file-content "fileb://$WORK_DIR/README.md" \
--file-path README.md \
--commit-message "Initial commit" \
--name "Tutorial User" \
--email "tutorial@example.com" \
--query 'commitId' --output text)
echo " Commit: $COMMIT_ID"

# Step 3: Get the file
echo "Step 3: Retrieving the file"
aws codecommit get-file --repository-name "$REPO_NAME" \
--file-path README.md \
--query '{Path:filePath,Size:fileSize,CommitId:commitId}' --output table

# Step 4: Create a branch
echo "Step 4: Creating a branch"
aws codecommit create-branch --repository-name "$REPO_NAME" \
--branch-name feature-branch --commit-id "$COMMIT_ID"
aws codecommit list-branches --repository-name "$REPO_NAME" \
--query 'branches' --output table

# Step 5: Add a file to the branch
echo "Step 5: Adding a file to the feature branch"
echo "console.log('Hello from CodeCommit');" > "$WORK_DIR/index.js"
aws codecommit put-file \
--repository-name "$REPO_NAME" \
--branch-name feature-branch \
--file-content "fileb://$WORK_DIR/index.js" \
--file-path src/index.js \
--commit-message "Add source file" \
--parent-commit-id "$COMMIT_ID" \
--query 'commitId' --output text > /dev/null
echo " File added to feature-branch"

# Step 6: Get differences between branches
echo "Step 6: Comparing branches"
aws codecommit get-differences \
--repository-name "$REPO_NAME" \
--before-commit-specifier main \
--after-commit-specifier feature-branch \
--query 'differences[].{Path:afterBlob.path,Type:changeType}' --output table

# Step 7: Get repository metadata
echo "Step 7: Repository metadata"
aws codecommit get-repository --repository-name "$REPO_NAME" \
--query 'repositoryMetadata.{Name:repositoryName,DefaultBranch:defaultBranch,Created:creationDate}' --output table

echo ""
echo "Tutorial complete."
echo "Do you want to clean up all resources? (y/n): "
read -r CHOICE
if [[ "$CHOICE" =~ ^[Yy]$ ]]; then
cleanup
else
echo "Manual cleanup:"
echo " aws codecommit delete-repository --repository-name $REPO_NAME"
fi
53 changes: 53 additions & 0 deletions tuts/098-aws-codebuild-gs/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,53 @@
# CodeBuild: Create a project and run a build

Create an S3-sourced CodeBuild project, run a build, and verify artifacts using the AWS CLI.

## Source

https://docs.aws.amazon.com/codebuild/latest/userguide/getting-started-cli.html

## Use case

- ID: codebuild/getting-started
- Phase: create
- Complexity: intermediate
- Core actions: codebuild:CreateProject, codebuild:StartBuild

## What it does

1. Creates an S3 bucket for source and artifacts
2. Creates source files (buildspec.yml + index.html) and uploads as zip
3. Creates an IAM service role for CodeBuild
4. Creates a build project with S3 source
5. Starts a build
6. Waits for completion and checks artifacts

## Running

```bash
bash aws-codebuild-gs.sh
```

## Resources created

- S3 bucket (source and artifacts)
- CodeBuild project
- IAM role (with S3 and CloudWatch Logs policies)
- CloudWatch log group (created automatically by CodeBuild)

No persistent resources remain after cleanup. The script prompts you to delete all resources when it finishes.

## Estimated time

- Run: ~37 seconds (includes build execution)

## Cost

CodeBuild free tier includes 100 build minutes per month on general1.small. No charges expected for this tutorial under the free tier.

## Related docs

- [Getting started with CodeBuild (CLI)](https://docs.aws.amazon.com/codebuild/latest/userguide/getting-started-cli.html)
- [Build specification reference](https://docs.aws.amazon.com/codebuild/latest/userguide/build-spec-ref.html)
- [Build environment reference](https://docs.aws.amazon.com/codebuild/latest/userguide/build-env-ref.html)
- [CodeBuild pricing](https://aws.amazon.com/codebuild/pricing/)
8 changes: 8 additions & 0 deletions tuts/098-aws-codebuild-gs/REVISION-HISTORY.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
# Revision History: 098-aws-codebuild-gs

## Shell (CLI script)

### 2026-04-14 v1 published
- Type: functional
- Initial version

Loading
Loading