Skip to content

Commit e0ae46e

Browse files
committed
Add developer-tools tutorials (batch 15)
1 parent 49f07d9 commit e0ae46e

9 files changed

Lines changed: 672 additions & 0 deletions

File tree

Lines changed: 64 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,64 @@
1+
# CodeCommit: Create a repository and manage code
2+
3+
Create a CodeCommit repository, add files, branch, compare changes, and retrieve metadata using the AWS CLI.
4+
5+
## Source
6+
7+
https://docs.aws.amazon.com/codecommit/latest/userguide/getting-started-cc.html
8+
9+
## Use case
10+
11+
- ID: codecommit/getting-started
12+
- Phase: create
13+
- Complexity: beginner
14+
- Core actions: codecommit:CreateRepository, codecommit:PutFile, codecommit:CreateBranch
15+
16+
## What it does
17+
18+
1. Creates a CodeCommit repository
19+
2. Adds a file using fileb://
20+
3. Retrieves the file metadata
21+
4. Creates a feature branch
22+
5. Adds a file to the feature branch
23+
6. Compares branches with get-differences
24+
7. Gets repository metadata
25+
26+
## Running
27+
28+
```bash
29+
bash aws-codecommit-gs.sh
30+
```
31+
32+
## Resources created
33+
34+
- CodeCommit repository
35+
36+
No persistent resources remain after cleanup. The script prompts you to delete the repository when it finishes.
37+
38+
## Estimated time
39+
40+
- Run: ~11 seconds
41+
42+
## Cost
43+
44+
CodeCommit is free for up to 5 active users per month (unlimited repositories). No charges for this tutorial under the free tier.
45+
46+
## Related docs
47+
48+
- [Getting started with CodeCommit](https://docs.aws.amazon.com/codecommit/latest/userguide/getting-started-cc.html)
49+
- [put-file CLI reference](https://docs.aws.amazon.com/cli/latest/reference/codecommit/put-file.html)
50+
- [Working with branches](https://docs.aws.amazon.com/codecommit/latest/userguide/how-to-create-branch.html)
51+
- [CodeCommit quotas](https://docs.aws.amazon.com/codecommit/latest/userguide/limits.html)
52+
- [CodeCommit pricing](https://aws.amazon.com/codecommit/pricing/)
53+
54+
---
55+
56+
## Appendix: Generation details
57+
58+
| Field | Value |
59+
|-------|-------|
60+
| Generation date | 2026-04-14 |
61+
| Source script | New, 100 lines |
62+
| Script test result | EXIT 0, 11s, 7 steps, no issues |
63+
| Issues encountered | file-content needs fileb:// not inline string (fixed) |
64+
| Iterations | v1 |
Lines changed: 108 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,108 @@
1+
# Create a CodeCommit repository and manage code
2+
3+
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.
4+
5+
## Prerequisites
6+
7+
- AWS CLI configured with credentials and a default region
8+
- Permissions for `codecommit:CreateRepository`, `codecommit:PutFile`, `codecommit:GetFile`, `codecommit:CreateBranch`, `codecommit:ListBranches`, `codecommit:GetDifferences`, `codecommit:GetRepository`, `codecommit:DeleteRepository`
9+
10+
## Step 1: Create a repository
11+
12+
```bash
13+
aws codecommit create-repository --repository-name "$REPO_NAME" \
14+
--repository-description "Tutorial repository" \
15+
--query 'repositoryMetadata.{Name:repositoryName,Id:repositoryId}' --output table
16+
```
17+
18+
CodeCommit returns the repository metadata including the name and unique ID.
19+
20+
## Step 2: Add a file
21+
22+
Write a file locally and upload it with `put-file`. Use `fileb://` to pass the file content as raw bytes:
23+
24+
```bash
25+
echo -e "# Tutorial Repository\n\nThis is a sample file." > "$WORK_DIR/README.md"
26+
COMMIT_ID=$(aws codecommit put-file \
27+
--repository-name "$REPO_NAME" \
28+
--branch-name main \
29+
--file-content "fileb://$WORK_DIR/README.md" \
30+
--file-path README.md \
31+
--commit-message "Initial commit" \
32+
--name "Tutorial User" \
33+
--email "tutorial@example.com" \
34+
--query 'commitId' --output text)
35+
```
36+
37+
The `fileb://` prefix tells the CLI to read the file as raw binary. This creates the `main` branch with the first commit.
38+
39+
## Step 3: Get the file
40+
41+
Retrieve file metadata from the repository:
42+
43+
```bash
44+
aws codecommit get-file --repository-name "$REPO_NAME" \
45+
--file-path README.md \
46+
--query '{Path:filePath,Size:fileSize,CommitId:commitId}' --output table
47+
```
48+
49+
## Step 4: Create a branch
50+
51+
Create a branch from the current commit and list all branches:
52+
53+
```bash
54+
aws codecommit create-branch --repository-name "$REPO_NAME" \
55+
--branch-name feature-branch --commit-id "$COMMIT_ID"
56+
aws codecommit list-branches --repository-name "$REPO_NAME" \
57+
--query 'branches' --output table
58+
```
59+
60+
## Step 5: Add a file to the branch
61+
62+
Add a new file to the feature branch. Pass `--parent-commit-id` to build on the branch tip:
63+
64+
```bash
65+
echo "console.log('Hello from CodeCommit');" > "$WORK_DIR/index.js"
66+
aws codecommit put-file \
67+
--repository-name "$REPO_NAME" \
68+
--branch-name feature-branch \
69+
--file-content "fileb://$WORK_DIR/index.js" \
70+
--file-path src/index.js \
71+
--commit-message "Add source file" \
72+
--parent-commit-id "$COMMIT_ID" \
73+
--query 'commitId' --output text
74+
```
75+
76+
## Step 6: Compare branches
77+
78+
Use `get-differences` to see what changed between `main` and `feature-branch`:
79+
80+
```bash
81+
aws codecommit get-differences \
82+
--repository-name "$REPO_NAME" \
83+
--before-commit-specifier main \
84+
--after-commit-specifier feature-branch \
85+
--query 'differences[].{Path:afterBlob.path,Type:changeType}' --output table
86+
```
87+
88+
## Step 7: Get repository metadata
89+
90+
```bash
91+
aws codecommit get-repository --repository-name "$REPO_NAME" \
92+
--query 'repositoryMetadata.{Name:repositoryName,DefaultBranch:defaultBranch,Created:creationDate}' \
93+
--output table
94+
```
95+
96+
## Cleanup
97+
98+
Delete the repository. This removes all branches, files, and commit history:
99+
100+
```bash
101+
aws codecommit delete-repository --repository-name "$REPO_NAME"
102+
```
103+
104+
The script automates all steps including cleanup:
105+
106+
```bash
107+
bash aws-codecommit-gs.sh
108+
```
Lines changed: 100 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,100 @@
1+
#!/bin/bash
2+
# Tutorial: Create a CodeCommit repository and manage code
3+
# Source: https://docs.aws.amazon.com/codecommit/latest/userguide/getting-started-cc.html
4+
5+
WORK_DIR=$(mktemp -d)
6+
LOG_FILE="$WORK_DIR/codecommit-$(date +%Y%m%d-%H%M%S).log"
7+
exec > >(tee -a "$LOG_FILE") 2>&1
8+
9+
REGION=${AWS_DEFAULT_REGION:-${AWS_REGION:-$(aws configure get region 2>/dev/null)}}
10+
if [ -z "$REGION" ]; then
11+
echo "ERROR: No AWS region configured. Set one with: export AWS_DEFAULT_REGION=us-east-1"
12+
exit 1
13+
fi
14+
export AWS_DEFAULT_REGION="$REGION"
15+
echo "Region: $REGION"
16+
17+
RANDOM_ID=$(openssl rand -hex 4)
18+
REPO_NAME="tutorial-repo-${RANDOM_ID}"
19+
20+
handle_error() { echo "ERROR on line $1"; trap - ERR; cleanup; exit 1; }
21+
trap 'handle_error $LINENO' ERR
22+
23+
cleanup() {
24+
echo ""
25+
echo "Cleaning up resources..."
26+
aws codecommit delete-repository --repository-name "$REPO_NAME" > /dev/null 2>&1 && \
27+
echo " Deleted repository $REPO_NAME"
28+
rm -rf "$WORK_DIR"
29+
echo "Cleanup complete."
30+
}
31+
32+
# Step 1: Create a repository
33+
echo "Step 1: Creating repository: $REPO_NAME"
34+
aws codecommit create-repository --repository-name "$REPO_NAME" \
35+
--repository-description "Tutorial repository" \
36+
--query 'repositoryMetadata.{Name:repositoryName,Id:repositoryId}' --output table
37+
38+
# Step 2: Add a file
39+
echo "Step 2: Adding a file to the repository"
40+
echo -e "# Tutorial Repository\n\nThis is a sample file created by the CodeCommit tutorial." > "$WORK_DIR/README.md"
41+
COMMIT_ID=$(aws codecommit put-file \
42+
--repository-name "$REPO_NAME" \
43+
--branch-name main \
44+
--file-content "fileb://$WORK_DIR/README.md" \
45+
--file-path README.md \
46+
--commit-message "Initial commit" \
47+
--name "Tutorial User" \
48+
--email "tutorial@example.com" \
49+
--query 'commitId' --output text)
50+
echo " Commit: $COMMIT_ID"
51+
52+
# Step 3: Get the file
53+
echo "Step 3: Retrieving the file"
54+
aws codecommit get-file --repository-name "$REPO_NAME" \
55+
--file-path README.md \
56+
--query '{Path:filePath,Size:fileSize,CommitId:commitId}' --output table
57+
58+
# Step 4: Create a branch
59+
echo "Step 4: Creating a branch"
60+
aws codecommit create-branch --repository-name "$REPO_NAME" \
61+
--branch-name feature-branch --commit-id "$COMMIT_ID"
62+
aws codecommit list-branches --repository-name "$REPO_NAME" \
63+
--query 'branches' --output table
64+
65+
# Step 5: Add a file to the branch
66+
echo "Step 5: Adding a file to the feature branch"
67+
echo "console.log('Hello from CodeCommit');" > "$WORK_DIR/index.js"
68+
aws codecommit put-file \
69+
--repository-name "$REPO_NAME" \
70+
--branch-name feature-branch \
71+
--file-content "fileb://$WORK_DIR/index.js" \
72+
--file-path src/index.js \
73+
--commit-message "Add source file" \
74+
--parent-commit-id "$COMMIT_ID" \
75+
--query 'commitId' --output text > /dev/null
76+
echo " File added to feature-branch"
77+
78+
# Step 6: Get differences between branches
79+
echo "Step 6: Comparing branches"
80+
aws codecommit get-differences \
81+
--repository-name "$REPO_NAME" \
82+
--before-commit-specifier main \
83+
--after-commit-specifier feature-branch \
84+
--query 'differences[].{Path:afterBlob.path,Type:changeType}' --output table
85+
86+
# Step 7: Get repository metadata
87+
echo "Step 7: Repository metadata"
88+
aws codecommit get-repository --repository-name "$REPO_NAME" \
89+
--query 'repositoryMetadata.{Name:repositoryName,DefaultBranch:defaultBranch,Created:creationDate}' --output table
90+
91+
echo ""
92+
echo "Tutorial complete."
93+
echo "Do you want to clean up all resources? (y/n): "
94+
read -r CHOICE
95+
if [[ "$CHOICE" =~ ^[Yy]$ ]]; then
96+
cleanup
97+
else
98+
echo "Manual cleanup:"
99+
echo " aws codecommit delete-repository --repository-name $REPO_NAME"
100+
fi
Lines changed: 65 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,65 @@
1+
# CodeBuild: Create a project and run a build
2+
3+
Create an S3-sourced CodeBuild project, run a build, and verify artifacts using the AWS CLI.
4+
5+
## Source
6+
7+
https://docs.aws.amazon.com/codebuild/latest/userguide/getting-started-cli.html
8+
9+
## Use case
10+
11+
- ID: codebuild/getting-started
12+
- Phase: create
13+
- Complexity: intermediate
14+
- Core actions: codebuild:CreateProject, codebuild:StartBuild
15+
16+
## What it does
17+
18+
1. Creates an S3 bucket for source and artifacts
19+
2. Creates source files (buildspec.yml + index.html) and uploads as zip
20+
3. Creates an IAM service role for CodeBuild
21+
4. Creates a build project with S3 source
22+
5. Starts a build
23+
6. Waits for completion and checks artifacts
24+
25+
## Running
26+
27+
```bash
28+
bash aws-codebuild-gs.sh
29+
```
30+
31+
## Resources created
32+
33+
- S3 bucket (source and artifacts)
34+
- CodeBuild project
35+
- IAM role (with S3 and CloudWatch Logs policies)
36+
- CloudWatch log group (created automatically by CodeBuild)
37+
38+
No persistent resources remain after cleanup. The script prompts you to delete all resources when it finishes.
39+
40+
## Estimated time
41+
42+
- Run: ~37 seconds (includes build execution)
43+
44+
## Cost
45+
46+
CodeBuild free tier includes 100 build minutes per month on general1.small. No charges expected for this tutorial under the free tier.
47+
48+
## Related docs
49+
50+
- [Getting started with CodeBuild (CLI)](https://docs.aws.amazon.com/codebuild/latest/userguide/getting-started-cli.html)
51+
- [Build specification reference](https://docs.aws.amazon.com/codebuild/latest/userguide/build-spec-ref.html)
52+
- [Build environment reference](https://docs.aws.amazon.com/codebuild/latest/userguide/build-env-ref.html)
53+
- [CodeBuild pricing](https://aws.amazon.com/codebuild/pricing/)
54+
55+
---
56+
57+
## Appendix: Generation details
58+
59+
| Field | Value |
60+
|-------|-------|
61+
| Generation date | 2026-04-14 |
62+
| Source script | New, 138 lines |
63+
| Script test result | EXIT 0, 37s, 6 steps, no issues |
64+
| Issues encountered | None |
65+
| Iterations | v1 |

0 commit comments

Comments
 (0)