> ## Documentation Index
> Fetch the complete documentation index at: https://docs.briankimemia.is-a.dev/llms.txt
> Use this file to discover all available pages before exploring further.

# Automate with CloudFormation

# 🌐 **Setting Up a Web Application on AWS**

Welcome to this detailed walkthrough on deploying a web application using AWS services. This guide will help you set up **IAM**, **Cloud9**, **CodeCommit**, **CodeArtifact**, and **CodeBuild** to build and deploy your applications efficiently.

***

## 🚀 **Step 1: Create an IAM User with Administrator Access**

Securely manage your AWS resources by creating a dedicated IAM user.

### **Instructions:**

1. **Sign in to the AWS Management Console** with your root account.
2. Navigate to the **IAM console**.
3. Go to **Users** > **Add user** and configure:
   * **User name**: e.g., `admin-user`
   * Enable **Programmatic access** and **AWS Management Console access**.
   * Attach the **AdministratorAccess** policy.
4. Download the credentials CSV file.
5. Log out and log in using the newly created IAM user.

:::tip
💡 Using an IAM user minimizes security risks compared to using the root account.
:::

:::danger
⚠️ Never use the root account for regular operations.
:::

***

## 🖥️ **Step 2: Set Up a Cloud9 Environment**

AWS Cloud9 provides a cloud-based IDE for developing applications directly within the AWS ecosystem.

### **Instructions:**

1. Open the **Cloud9 console** and click **Create environment**.
2. Configure your environment:
   * **Name**: `NextWorkIDE`
   * **Instance type**: `t2.micro`
   * **Platform**: Amazon Linux 2
3. Click **Create environment** and wait for the setup to complete.

:::info
💡 `t2.micro` is free-tier eligible, making it ideal for development.
:::

***

## ☕ **Step 3: Install Maven and Java**

Ensure your Cloud9 environment has the necessary tools installed.

### **Instructions:**

1. Open the Cloud9 terminal.
2. Install Java and Maven by running:

```bash theme={null}
sudo yum install -y java-1.8.0-openjdk
sudo yum install -y maven
```

3. Verify the installations:

```bash theme={null}
java -version
mvn -version
```

***

## 🗃️ **Step 4: Create a CodeCommit Repository**

AWS CodeCommit is a secure, scalable, and Git-based source control service.

### **Instructions:**

1. Open the **CodeCommit console**.
2. Click **Create repository** and configure:
   * **Name**: `nextwork-web-project`
3. Clone the repository into your Cloud9 environment:

```bash theme={null}
git clone https://git-codecommit.<region>.amazonaws.com/v1/repos/nextwork-web-project
```

***

## 📦 **Step 5: Set Up CodeArtifact**

AWS CodeArtifact simplifies dependency management with a fully managed package repository service.

### **Instructions:**

1. Open the **CodeArtifact console**.
2. Create a **Domain** and **Repository**:
   * **Domain Name**: `nextwork`
   * **Repository Name**: `nextwork-packages`
3. Configure your Maven settings file (`~/.m2/settings.xml`) to use CodeArtifact:

```xml theme={null}
<settings>
  <profiles>
    <profile>
      <id>codeartifact</id>
      <repositories>
        <repository>
          <id>codeartifact</id>
          <url>https://<domain>.d.codeartifact.<region>.amazonaws.com/maven/nextwork/nextwork-packages</url>
          <releases>
            <enabled>true</enabled>
          </releases>
        </repository>
      </repositories>
    </profile>
  </profiles>
  <activeProfiles>
    <activeProfile>codeartifact</activeProfile>
  </activeProfiles>
</settings>
```

:::tip
💡 CodeArtifact integrates seamlessly with Maven, npm, and other package managers.
:::

***

## ✅ **Step 6: Test CodeArtifact Connection**

Verify that your project connects successfully to CodeArtifact.

### **Instructions:**

1. Navigate to your project directory.
2. Run the following command:

```bash theme={null}
mvn compile
```

***

## 🗂️ **Step 7: Create an S3 Bucket for Build Artifacts**

AWS S3 will be used to store build outputs generated by CodeBuild.

### **Instructions:**

1. Open the **S3 console**.
2. Click **Create bucket**:
   * **Bucket Name**: `nextwork-build-artifacts`
   * Ensure the bucket is in the same region as your other AWS resources.

:::danger
⚠️ S3 bucket names must be globally unique.
:::

***

## 🛠️ **Step 8: Set Up CodeBuild**

AWS CodeBuild compiles your code and produces build artifacts.

### **Instructions:**

1. Open the **CodeBuild console** and click **Create project**.
2. Configure your build project:
   * **Name**: `nextwork-web-build`
   * **Source**: CodeCommit repository (`nextwork-web-project`)
   * Add the following Buildspec commands:

```yaml theme={null}
version: 0.2
phases:
  build:
    commands:
      - mvn clean package
artifacts:
  files:
    - target/*.jar
```

3. Specify your S3 bucket for build artifacts.

***

## 🎉 **Conclusion**

Congratulations! You have successfully set up a web application using IAM, Cloud9, CodeCommit, CodeArtifact, and CodeBuild. This pipeline ensures a secure and scalable environment for your applications.

For more information, refer to the [AWS Documentation](https://docs.aws.amazon.com/).

## 📧 Contact

For questions or feedback, reach out:

📨 Email: [projects@briankimemia.is-a.dev](mailto:projects@briankimemia.is-a.dev)
🌐 Portfolio: [Brian Kimemia](https://briankimemia.is-a.dev/)
**GitHub:** [BrianKN019](https://github.com/BrianKN019)

***

**Thank you for exploring this project! Let’s innovate and build secure AWS solutions together. 🚀**
