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

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:

{
  "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

git init
git remote add origin <CodeCommit HTTPS URL>

💡 Tip

Use AWS CLI to fetch the repository URL dynamically:

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

aws codeartifact login \
  --tool npm \
  --domain <DOMAIN_NAME> \
  --domain-owner <AWS_ACCOUNT_ID>
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.

aws s3 mb s3://nextwork-build-artifacts

💡 Tip

Enable versioning for enhanced reliability:

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:

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

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 🌐 Portfolio: Brian Kimemia GitHub: BrianKN019


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