> ## 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.

# AWS Web App Deployment Guide

> Step-by-step guide for deploying a web app using AWS services.

# 🚀 AWS Web App Deployment Guide

Welcome to this comprehensive guide on deploying your web application using AWS services. This guide simplifies the process and ensures you build a scalable and secure application infrastructure. 🌟

***

## **1. Set Up IAM Roles and Policies**

AWS Identity and Access Management (IAM) ensures secure access to your services. Create a dedicated role for CodeBuild.

```bash theme={null}
aws iam create-role \
  --role-name CodeBuildServiceRole \
  --assume-role-policy-document file://trust-policy.json
```

### 💡 **Tip**

Ensure your `trust-policy.json` allows `codebuild.amazonaws.com` to assume the role.

**Minimal Trust Policy Example:**

```json theme={null}
{
  "Version": "2012-10-17",
  "Statement": [
    {
      "Effect": "Allow",
      "Principal": { "Service": "codebuild.amazonaws.com" },
      "Action": "sts:AssumeRole"
    }
  ]
}
```

***

## **2. Launch AWS Cloud9 IDE**

AWS Cloud9 provides a cloud-based IDE for coding and managing resources.

1. Navigate to the **Cloud9 Console**.
2. Create a new environment and select an appropriate instance type.

### ⚠️ **Disclaimer**

Using large instance types in Cloud9 may incur higher costs. Always choose resources based on your project requirements.

***

## **3. Initialize Git and Connect to CodeCommit**

```bash theme={null}
git init
git remote add origin <CodeCommit HTTPS URL>
```

### 💡 **Tip**

Use AWS CLI to fetch the repository URL dynamically:

```bash theme={null}
aws codecommit get-repository \
  --repository-name <REPO_NAME> \
  --query 'repositoryMetadata.cloneUrlHttp' --output text
```

***

## **4. Set Up AWS CodeArtifact**

Store dependencies securely in CodeArtifact.

### **Setup Commands**

```bash theme={null}
aws codeartifact login \
  --tool npm \
  --domain <DOMAIN_NAME> \
  --domain-owner <AWS_ACCOUNT_ID>
```

```bash theme={null}
npm config set registry <CODEARTIFACT_REGISTRY_URL>
```

### ⚠️ **Warning**

Ensure your CodeArtifact repository is in the same region as your Cloud9 environment.

***

## **5. Configure S3 for Artifact Storage**

Create an S3 bucket for storing build artifacts.

```bash theme={null}
aws s3 mb s3://nextwork-build-artifacts
```

### 💡 **Tip**

Enable versioning for enhanced reliability:

```bash theme={null}
aws s3api put-bucket-versioning \
  --bucket nextwork-build-artifacts \
  --versioning-configuration Status=Enabled
```

***

## **6. Define buildspec.yml File**

`buildspec.yml` defines the build process for your application.

**Sample File:**

```yaml theme={null}
version: 0.2
phases:
  install:
    commands:
      - echo Installing dependencies...
      - npm install
  build:
    commands:
      - echo Building application...
      - npm run build
artifacts:
  files:
    - '**/*'
    - '!node_modules/**/*'
```

### ⚠️ **Disclaimer**

Avoid including sensitive files in the artifact path.

***

## **7. Automate Infrastructure with CloudFormation**

CloudFormation simplifies resource provisioning via code.

### **Template Example**

```yaml theme={null}
AWSTemplateFormatVersion: '2010-09-09'
Resources:
  S3Bucket:
    Type: AWS::S3::Bucket
    Properties:
      BucketName: !Sub 'nextwork-build-${AWS::AccountId}'
  CodeCommitRepo:
    Type: AWS::CodeCommit::Repository
    Properties:
      RepositoryName: nextwork-web
```

### 💡 **Tip**

Use the AWS Management Console to validate your CloudFormation templates before deployment.

***

## **8. Deploy CloudFormation Template**

1. Navigate to **CloudFormation Console**.
2. Create a stack using your `nextwork-template.yaml`.
3. Monitor the stack creation progress.

***

## 🌟 **Congratulations!**

You’ve successfully set up your AWS web application infrastructure. 🎉 Keep exploring and iterating on your deployment pipeline for even better results. Happy coding! 🚀

## 📧 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. 🚀**
