diff --git a/AWS_ECS_Labs/.github/workflows/02-ECR-ECS.yml b/AWS_ECS_Labs/.github/workflows/02-ECR-ECS.yml new file mode 100644 index 0000000..9a9f048 --- /dev/null +++ b/AWS_ECS_Labs/.github/workflows/02-ECR-ECS.yml @@ -0,0 +1,62 @@ +name: "ECR-ECS-Deployment" +on: + workflow_dispatch: + +jobs: + ECR_ECS_Deployment: + name: Build Docker Image And Push To ECR And Deploy To ECS + runs-on: ubuntu-latest + steps: + - name: Checkout + uses: actions/checkout@v2 + + - name: Setup AWS ECR Details + uses: aws-actions/configure-aws-credentials@v1 + with: + aws-access-key-id: ${{ secrets.AWS_ACCESS_KEY_ID }} + aws-secret-access-key: ${{ secrets.AWS_SECRET_ACCESS_KEY }} + aws-region: ${{secrets.AWS_REGION}} + + - name: Login to Amazon ECR + id: login-pf-aws-ecr + uses: aws-actions/amazon-ecr-login@v1 + + - name: Build and push the tagged docker image to Amazon ECR + id : containerImage + env: + ECR_REGISTRY: ${{ steps.login-pf-aws-ecr.outputs.registry }} + ECR_REPOSITORY: ${{secrets.AWS_ECR_REPO}} + IMAGE_TAG: latest + run: | + docker build -t $ECR_REGISTRY/$ECR_REPOSITORY:$IMAGE_TAG . + docker push $ECR_REGISTRY/$ECR_REPOSITORY:$IMAGE_TAG + + - name: ECR Status Check + if: steps.containerImage.outcome == 'failure' + run: exit 1 + + - name: Setup Terraform + uses: hashicorp/setup-terraform@v2.0.2 + with: + terraform_version: latest + cli_config_credentials_token: ${{ secrets.TFC_API_TOKEN }} + + - name: Terraform Init + id: init + run: terraform init + + - name: Terraform Validate + id: validate + run: terraform validate + + - name: Terraform Plan + id: plan + run: terraform plan + continue-on-error: true + + - name: Terraform Plan Status + if: steps.plan.outcome == 'failure' + run: exit 1 + + - name: Terraform Apply + run: terraform apply -auto-approve \ No newline at end of file diff --git a/AWS_ECS_Labs/Dockerfile b/AWS_ECS_Labs/Dockerfile new file mode 100644 index 0000000..52753eb --- /dev/null +++ b/AWS_ECS_Labs/Dockerfile @@ -0,0 +1,13 @@ +FROM python:3.10-alpine3.18 + +# WORKDIR /app + +COPY . . + +RUN pip install -r requirements.txt + +EXPOSE 5000 + +ENV PYTHONUNBUFFERED=1 + +CMD ["python" ,"app.py"] \ No newline at end of file diff --git a/AWS_ECS_Labs/ECS/main.tf b/AWS_ECS_Labs/ECS/main.tf new file mode 100644 index 0000000..23974fc --- /dev/null +++ b/AWS_ECS_Labs/ECS/main.tf @@ -0,0 +1,73 @@ + + +data "aws_vpc" "existing" { + id = var.vpc_id +} + + +resource "aws_security_group" "ecs_sg" { + vpc_id = data.aws_vpc.existing.id + name = "ecs-security-group" + # Inbound and outbound rules + ingress { + from_port = 5000 + to_port = 5000 + protocol = "tcp" + cidr_blocks = ["0.0.0.0/0"] + } + egress { + from_port = 0 + to_port = 0 + protocol = "-1" + cidr_blocks = ["0.0.0.0/0"] + } +} + + +resource "aws_ecs_task_definition" "task_definition" { + family = var.cluster_service_task_name + network_mode = "awsvpc" + memory = "512" + requires_compatibilities = ["FARGATE"] + + + execution_role_arn = var.execution_role_arn + + + container_definitions = jsonencode([ + { + name = "flask-api-container" + image = var.image_id + cpu = 256 + memory = 512 + port_mappings = [ + { + container_port = 5000 + host_port = 5000 + protocol = "tcp" + } + ] + } + ]) + + cpu = "256" +} + + +resource "aws_ecs_cluster" "ecs_cluster" { + name = var.cluster_name +} + +resource "aws_ecs_service" "service" { + name = var.cluster_service_name + cluster = aws_ecs_cluster.ecs_cluster.id + task_definition = aws_ecs_task_definition.task_definition.arn + desired_count = 1 + launch_type = "FARGATE" + + network_configuration { + subnets = [var.vpc_id_subnet_list[0], var.vpc_id_subnet_list[1], var.vpc_id_subnet_list[2], var.vpc_id_subnet_list[3]] + security_groups = [aws_security_group.ecs_sg.id] + assign_public_ip = true + } +} \ No newline at end of file diff --git a/AWS_ECS_Labs/ECS/variables.tf b/AWS_ECS_Labs/ECS/variables.tf new file mode 100644 index 0000000..d819e2c --- /dev/null +++ b/AWS_ECS_Labs/ECS/variables.tf @@ -0,0 +1,16 @@ + + +variable "vpc_id" {} + +variable "cluster_name" {} + +variable "cluster_service_name" {} + +variable "cluster_service_task_name" {} + +variable "image_id" {} + +variable "vpc_id_subnet_list" {} + +variable "execution_role_arn" {} + diff --git a/AWS_ECS_Labs/README.md b/AWS_ECS_Labs/README.md new file mode 100644 index 0000000..22fd97d --- /dev/null +++ b/AWS_ECS_Labs/README.md @@ -0,0 +1,2 @@ +# AWS_ECS_Labs +A lab session on Deploying Images to Amazon ECS via ECR diff --git a/AWS_ECS_Labs/app.py b/AWS_ECS_Labs/app.py new file mode 100644 index 0000000..ccbfb86 --- /dev/null +++ b/AWS_ECS_Labs/app.py @@ -0,0 +1,32 @@ +from flask import Flask +import random +import time + +app = Flask(__name__) + +@app.route('/time') +def get_current_time(): + timestamp = str(int(time.time())) + response = { + "time": timestamp, + "message": "success", + "httpsresponse": "200", + "testedTIME": "yes" + } + return response + +## Add a new route here +@app.route('/random') +def get_random_numbers(): + numbers = [random.randint(0, 5) for _ in range(10)] + response = { + "random_number": numbers, + "message": "success", + "httpsresponse": "200", + "testedTIME": "yes" + } + return response + + +if __name__ == '__main__': + app.run(host='0.0.0.0', port=5000) \ No newline at end of file diff --git a/AWS_ECS_Labs/main.tf b/AWS_ECS_Labs/main.tf new file mode 100644 index 0000000..b95a612 --- /dev/null +++ b/AWS_ECS_Labs/main.tf @@ -0,0 +1,12 @@ +/* +module "ecs" { + source = "./ECS" + vpc_id = "vpc-29568551" + cluster_name = "demo-api-cluster" + cluster_service_name = "cloudquicklabs-api-service" + cluster_service_task_name = "cloudquicklabs-api-task" + vpc_id_subnet_list = ["subnet-470f460c", " subnet-34b48b6e", "subnet-9b072be2", "subnet-f78ebadf"] + execution_role_arn = "arn:aws:iam::357171621133:role/ETLlambdaAccessRole" + image_id = "357171621133.dkr.ecr.us-west-2.amazonaws.com/ecsdemo:latest" +} +*/ diff --git a/AWS_ECS_Labs/provider.tf b/AWS_ECS_Labs/provider.tf new file mode 100644 index 0000000..74b24fb --- /dev/null +++ b/AWS_ECS_Labs/provider.tf @@ -0,0 +1,32 @@ +terraform { + + required_providers { + aws = { + source = "hashicorp/aws" + version = "~> 4.15.0" + } + + random = { + source = "hashicorp/random" + version = "3.1.0" + } + kubernetes = { + source = "hashicorp/kubernetes" + version = ">= 2.0.1" + } + } + +backend "remote" { + hostname = "app.terraform.io" + organization = "CloudQuickLabs" + + workspaces { + name = "AWSECS" + } + } +} + +provider "aws" { + region = "us-west-2" +} + diff --git a/AWS_ECS_Labs/requirements.txt b/AWS_ECS_Labs/requirements.txt new file mode 100644 index 0000000..c1894ab --- /dev/null +++ b/AWS_ECS_Labs/requirements.txt @@ -0,0 +1 @@ +Flask>=1.1.1 \ No newline at end of file diff --git a/AWS_LookOut_Vison/1-14.jpg b/AWS_LookOut_Vison/1-14.jpg new file mode 100644 index 0000000..14f9646 Binary files /dev/null and b/AWS_LookOut_Vison/1-14.jpg differ diff --git a/AWS_LookOut_Vison/106990856_Subscription_S.jpg b/AWS_LookOut_Vison/106990856_Subscription_S.jpg new file mode 100644 index 0000000..6c510af Binary files /dev/null and b/AWS_LookOut_Vison/106990856_Subscription_S.jpg differ diff --git a/AWS_LookOut_Vison/37-376750_2-series-bmw-cars-hd-png-download.png b/AWS_LookOut_Vison/37-376750_2-series-bmw-cars-hd-png-download.png new file mode 100644 index 0000000..fe7f0b5 Binary files /dev/null and b/AWS_LookOut_Vison/37-376750_2-series-bmw-cars-hd-png-download.png differ diff --git a/AWS_LookOut_Vison/4-47502_car-clipart-suzuki-celerio-new-regular-cab-2006.png b/AWS_LookOut_Vison/4-47502_car-clipart-suzuki-celerio-new-regular-cab-2006.png new file mode 100644 index 0000000..4c34f10 Binary files /dev/null and b/AWS_LookOut_Vison/4-47502_car-clipart-suzuki-celerio-new-regular-cab-2006.png differ diff --git a/AWS_LookOut_Vison/602-6023427_drawn-bmw-normal-car-1-series-bmw-2.png b/AWS_LookOut_Vison/602-6023427_drawn-bmw-normal-car-1-series-bmw-2.png new file mode 100644 index 0000000..1aea484 Binary files /dev/null and b/AWS_LookOut_Vison/602-6023427_drawn-bmw-normal-car-1-series-bmw-2.png differ diff --git a/AWS_LookOut_Vison/65955744-repair-of-broken-car-engine-closeup.jpg b/AWS_LookOut_Vison/65955744-repair-of-broken-car-engine-closeup.jpg new file mode 100644 index 0000000..c6e6db9 Binary files /dev/null and b/AWS_LookOut_Vison/65955744-repair-of-broken-car-engine-closeup.jpg differ diff --git a/AWS_LookOut_Vison/674-6741056_new-bmw-2-series-image-link-bmw-2017.png b/AWS_LookOut_Vison/674-6741056_new-bmw-2-series-image-link-bmw-2017.png new file mode 100644 index 0000000..8d7e9a2 Binary files /dev/null and b/AWS_LookOut_Vison/674-6741056_new-bmw-2-series-image-link-bmw-2017.png differ diff --git a/AWS_LookOut_Vison/7661af948f4f45f1941428b010a00a67_800.jpg b/AWS_LookOut_Vison/7661af948f4f45f1941428b010a00a67_800.jpg new file mode 100644 index 0000000..4d6669d Binary files /dev/null and b/AWS_LookOut_Vison/7661af948f4f45f1941428b010a00a67_800.jpg differ diff --git a/AWS_LookOut_Vison/MicrosoftTeams-image-5.jpg b/AWS_LookOut_Vison/MicrosoftTeams-image-5.jpg new file mode 100644 index 0000000..c43104c Binary files /dev/null and b/AWS_LookOut_Vison/MicrosoftTeams-image-5.jpg differ diff --git a/AWS_LookOut_Vison/The-Most-Beautiful-Engine-Bays-of-All-Time-Gear-Patrol-Lead-Full.jpg b/AWS_LookOut_Vison/The-Most-Beautiful-Engine-Bays-of-All-Time-Gear-Patrol-Lead-Full.jpg new file mode 100644 index 0000000..c92069a Binary files /dev/null and b/AWS_LookOut_Vison/The-Most-Beautiful-Engine-Bays-of-All-Time-Gear-Patrol-Lead-Full.jpg differ diff --git a/AWS_LookOut_Vison/Tire-Sidewall-Damage-How-Much-Damage-Is-Too-Much.jpg b/AWS_LookOut_Vison/Tire-Sidewall-Damage-How-Much-Damage-Is-Too-Much.jpg new file mode 100644 index 0000000..8d99835 Binary files /dev/null and b/AWS_LookOut_Vison/Tire-Sidewall-Damage-How-Much-Damage-Is-Too-Much.jpg differ diff --git a/AWS_LookOut_Vison/_600x339_2014_03_18_15.57.55.jpg b/AWS_LookOut_Vison/_600x339_2014_03_18_15.57.55.jpg new file mode 100644 index 0000000..fac2e98 Binary files /dev/null and b/AWS_LookOut_Vison/_600x339_2014_03_18_15.57.55.jpg differ diff --git a/AWS_LookOut_Vison/blownengine.jpeg b/AWS_LookOut_Vison/blownengine.jpeg new file mode 100644 index 0000000..4b02fec Binary files /dev/null and b/AWS_LookOut_Vison/blownengine.jpeg differ diff --git a/AWS_LookOut_Vison/car-engine-damage-from-overheating.jpg b/AWS_LookOut_Vison/car-engine-damage-from-overheating.jpg new file mode 100644 index 0000000..a0e2ff8 Binary files /dev/null and b/AWS_LookOut_Vison/car-engine-damage-from-overheating.jpg differ diff --git a/AWS_LookOut_Vison/car-engine-failure.jpg b/AWS_LookOut_Vison/car-engine-failure.jpg new file mode 100644 index 0000000..90e337a Binary files /dev/null and b/AWS_LookOut_Vison/car-engine-failure.jpg differ diff --git a/AWS_LookOut_Vison/download.jpg b/AWS_LookOut_Vison/download.jpg new file mode 100644 index 0000000..e5e957a Binary files /dev/null and b/AWS_LookOut_Vison/download.jpg differ diff --git a/AWS_LookOut_Vison/images (1).jpg b/AWS_LookOut_Vison/images (1).jpg new file mode 100644 index 0000000..0c073b4 Binary files /dev/null and b/AWS_LookOut_Vison/images (1).jpg differ diff --git a/AWS_LookOut_Vison/images.jpg b/AWS_LookOut_Vison/images.jpg new file mode 100644 index 0000000..0e8158f Binary files /dev/null and b/AWS_LookOut_Vison/images.jpg differ diff --git a/AWS_LookOut_Vison/istockphoto-1393547255-170667a.jpg b/AWS_LookOut_Vison/istockphoto-1393547255-170667a.jpg new file mode 100644 index 0000000..8c8402b Binary files /dev/null and b/AWS_LookOut_Vison/istockphoto-1393547255-170667a.jpg differ diff --git a/AWS_LookOut_Vison/istockphoto-1393547255-612x612.jpg b/AWS_LookOut_Vison/istockphoto-1393547255-612x612.jpg new file mode 100644 index 0000000..f4d6482 Binary files /dev/null and b/AWS_LookOut_Vison/istockphoto-1393547255-612x612.jpg differ diff --git a/AWS_LookOut_Vison/istockphoto-1425966422-612x612.jpg b/AWS_LookOut_Vison/istockphoto-1425966422-612x612.jpg new file mode 100644 index 0000000..c8c4b5d Binary files /dev/null and b/AWS_LookOut_Vison/istockphoto-1425966422-612x612.jpg differ diff --git a/AWS_LookOut_Vison/istockphoto-465663510-612x612.jpg b/AWS_LookOut_Vison/istockphoto-465663510-612x612.jpg new file mode 100644 index 0000000..cb84fe2 Binary files /dev/null and b/AWS_LookOut_Vison/istockphoto-465663510-612x612.jpg differ diff --git a/AWS_LookOut_Vison/kia-sportage-engine-1.jpg b/AWS_LookOut_Vison/kia-sportage-engine-1.jpg new file mode 100644 index 0000000..0ebb540 Binary files /dev/null and b/AWS_LookOut_Vison/kia-sportage-engine-1.jpg differ diff --git a/AWS_LookOut_Vison/mceu_70678983211654608862327_1654608862.jpg b/AWS_LookOut_Vison/mceu_70678983211654608862327_1654608862.jpg new file mode 100644 index 0000000..b28fc48 Binary files /dev/null and b/AWS_LookOut_Vison/mceu_70678983211654608862327_1654608862.jpg differ diff --git a/AWS_LookOut_Vison/resizer.jpg b/AWS_LookOut_Vison/resizer.jpg new file mode 100644 index 0000000..7348de1 Binary files /dev/null and b/AWS_LookOut_Vison/resizer.jpg differ diff --git a/AWS_LookOut_Vison/shutterstock_1064744909.jpeg b/AWS_LookOut_Vison/shutterstock_1064744909.jpeg new file mode 100644 index 0000000..2a23dfd Binary files /dev/null and b/AWS_LookOut_Vison/shutterstock_1064744909.jpeg differ diff --git a/AWS_LookOut_Vison/ttk-image-engine_05_01-2.png b/AWS_LookOut_Vison/ttk-image-engine_05_01-2.png new file mode 100644 index 0000000..b93dba4 Binary files /dev/null and b/AWS_LookOut_Vison/ttk-image-engine_05_01-2.png differ