Monday, March 28, 2022

AWS Containers - ECS (Elastic Container Service)


ECS is a cluster created on the AWS environment for supporting container services. Container services can be implemented using Fargate which is a serverless solution or using EC2 instance-based solution. 

1. Create a FARGATE cluster.

Step 1: Select ECS service and Click on Get Started.

Step 2: Here we need to create container, task, service, cluster definitions

Step 3: For container:

  • Select nginx application.

Step 4: For task:

  • If you want to change the task definition then click on Edit button and make the changes like name of the task or Memory and CPU, etc. 

Step 5: Click on Next button

Step 6: For service:

  • Define service and keep the configuration as it is (if you want to change the configuration then click on Edit button) 

Step 7: click on next button.

Step 8: Cluster definitions:

  • Provide cluster name
  • This will auto create a VPC for you so ensure your VPC space is avaialble (only 5 VPC per region).

Step 9: Click on next

Step 10: Review and click on Create button.

Step 11: Click on View Service Button.

Step 12: Click on Task tab

Step 13: Copy the public IP 13.55.68.139 and browse it in the browser and you should be able to see the nginx web page.

Step 14: Delete the cluster 
when you delete this cluster, the ECS resources such as VPC will be auto deleted.

IBM Capstone Part 1.2 - GitLab with Kubernetes

Prerequisite:

3 Vms ubuntu in Aws 

1 machine GitLab runner is already running

Docker is installed

Step 1: On All the machine install kubernetes agent and common components

  • sudo apt-get update && sudo apt-get install -y apt-transport-https curl
  • curl -s https://packages.cloud.google.com/apt/doc/apt-key.gpg | sudo apt-key add -
  • cat <<EOF | sudo tee /etc/apt/sources.list.d/kubernetes.list
    deb https://apt.kubernetes.io/ kubernetes-xenial main
    EOF
  • sudo apt-get update
  • sudo apt install -qq -y kubeadm=1.21.0-00 kubelet=1.21.0-00 kubectl=1.21.0-00
  • sudo apt-mark hold kubelet kubeadm kubectl

  • sudo apt update
  • sudo apt install docker.io -y

Step 2: Run below commands on Gitlab server machine

  • sudo kubeadm init --apiserver-advertise-address=172.31.29.213 --pod-network-cidr=192.168.0.0/16
    • if abovecannot (like it shows preflight error): type:
      kubeadm reset
  • mkdir -p $HOME/.kube
  • sudo cp -i /etc/kubernetes/admin.conf $HOME/.kube/config
  • sudo chown $(id -u):$(id -g) $HOME/.kube/config
  • kubectl create -f https://docs.projectcalico.org/v3.18/manifests/calico.yaml

Step 3: copy and make the worker ready. but if they cant be ready, this might help:

https://stackoverflow.com/questions/54728254/kubernetes-kubeadm-init-fails-due-to-dial-tcp-127-0-0-110248-connect-connecti


Step 4: Install helm on Master server only.

  • curl https://baltocdn.com/helm/signing.asc | sudo apt-key add -
  • sudo apt-get install apt-transport-https --yes
  • echo "deb https://baltocdn.com/helm/stable/debian/ all main" | sudo tee /etc/apt/sources.list.d/helm-stable-debian.list
  • sudo apt-get update
  • sudo apt-get install helm





Gitlab Code Coverage - JACOCO

Clone the below repository

https://gitlab.com/ramansharma95/test.git


Go to Gitlab Project and Go to Settings --> CICD --> General Pipeline

In the test coverage parsing add below expression

Total.*?([0-9]{1,3})%

Go to General Settings ---> Badges

Badge name is Coverage

Link

https://gitlab.com/ramansharma95/%{project_path}/badges/%{default_branch}/coverage.svg


Badge Image URL

https://gitlab.com/%{project_path}/badges/%{default_branch}/coverage.svg?style=flat


Go to test folder

mvn clean package command

go to target/site/jacoco/index.html


IBM Capstone Raman Guide

 Prerequisite: 

            Valid Gitlab Account

            Valid Dockerhub Account and login to local system with that credentials

           

Step 1: Create a single EC2 instance

            AMI : ubuntu 18.04

           Instance Type: t2.medium

           SG : All traffic to open

           key: some valid key

Step 2: Install maven, docker ,gitlab runner

           sudo apt update

Maven:

           sudo apt install maven -y

Docker:

           sudo apt install docker.io -y

GitLab runner:

curl -L "https://packages.gitlab.com/install/repositories/runner/gitlab-runner/script.deb.sh" | sudo bash

sudo apt-get install gitlab-runner

sudo gitlab-runner register

sudo vi /etc/sudoers

and add below entry after root user info and save your file

gitlab-runner ALL=(ALL) NOPASSWD: ALL

GitLab deploy keys

ssh-keygen

cat and copy 

Make branches for dev1, dev2, and release

git branch

git checkout

Code from dev1 or dev2 ---> release branch ---> main branch

   

Step 4: Create a sample maven quick start project using maven archetype.

mvn generate:archetype

com.irfan

artifactID: capstone-maven

Edit pom.xml and put in sonarcloud dependency

<properties>
  <sonar.organization>ibm-capstone-sonarcloud</sonar.organization>
</properties>

Put in sonarcloud variables in the GitLab variables

sonar token

sonar url

Config git global

git config --global user.name ifanrahman

git config --global user.email ifanrahman@gmail.com

make a Dockerfile

craft a robust .gitlab-ci.yml

push into remote repo



Step 10: To create a Dockerfile - multistage to define the steps to include and deploy your jar file.

Step 11: Create Gitlab CI/CD Pipeline where you need to define following stages

  In each stage create a log file and store the information that stage is completed or not.

    build stage:- Create the jar file using mvn clean package command

   builddockerimg stage: Build Dockerfile by adding jar file in the dockerimage.

   ImageScan Stage: docker scan for docker images

   ImagePush stage: docker image is to be pushed to docker hub

   test stage: jar file get created---pass

  Parallel test stage: container from docker image and if you find the container get created it means test is passed


Step 12: In k8s cluster run the NodePort service to expose an application on the browser

Friday, March 25, 2022

AWS Security, Identity & Compliance - WAF and Shield

 


AWS WAF is a web application firewall service that helps protect your web apps from common exploits that could affect app availability, compromise security, or consume excessive resources.

AWS Shield provides expanded DDoS attack protection for your AWS resources. Get 24/7 support from our DDoS response team and detailed visibility into DDoS events.

AWS Firewall Manager simplifies your AWS WAF administration and maintenance tasks across multiple accounts and resources.


Step 1: Create 2 EC2 instances in different AZs and install httpd and update the index.html file under /var/www/html folder so that you can differentiate these 2 instances' webservers.

  • sudo su
  • yum install httpd -y
  • systemctl start httpd
  • echo "<h1> Server1 </h1>" > /var/www/html/index.htm
  • echo "<h1> Server2 </h1>" > /var/www/html/index.html

Step 2: Create Application LB by creating a single Target Group by registering both instances. (Click on Target Group rather than Application Load Balancing)

Step 3: Get your public IP address so that we can restrict to access ALB from the system.

Step 4: Go to WAF---> IPSets

Step 5: Set following Configuration

  • IP Set Name: MyIPSet
  • Region: Select your region
  • Add Your IP Address in IP addresses.like 27.7.187.246/32
  • Click on Create IP Set

Step 6: Select Web ACL --> Click on Create WebACL

Step 7: Provide the details like

  • Name: MyWebAcl
  • Click on Add AWS resources button and select your ALB
  • Click on Next Button

Step 8: Add Rule by click on Add Rule--> Add my own rule.

Step 9: Name the rule and select IPSet and select your IP, select and click on Block access

Step 10: Reset of the options no change and Create on WebACL button.

Try to access your ALB on web it should be forbidden


to delete


need to delete the application load balancer first,

then delete target groups,

then delete webACLS,

then delete IPsets,

AWS Security, Identity & Compliance - Secrets Manager

 


KMS – Key management Secret

Automatic rotation schedule (change the secret every n days)

There will be sample code for java, java2, javascript, python, go, c#

then store your secret

Thursday, March 24, 2022

AWS Containers - EKS NodeGroup Operations



1. get node group details of the cluster
eksctl get nodegroup --cluster EKS-raman-cluster

2. scale-out node group to 5 nodes and then check no. of instances created in EC2
eksctl scale nodegroup --cluster EKS-raman-cluster --name ng-1 --nodes 5 --nodes-max 5

3. scale in node group to 3 nodes and then check no. of instances created in EC2
eksctl scale nodegroup --cluster EKS-raman-cluster --name ng-1 --nodes 3

To create a new node group with spot instance and demand instance

Step 1: create a yaml file as mentioned below (nodegroup.yml)

apiVersion: eksctl.io/v1alpha5 
kind: ClusterConfig

metadata: 
    name: EKS-raman-cluster 
    region: us-east-1 

nodeGroups: 
     - name: ng-1 
     instanceType: t2.small 
     desiredCapacity: 3 
     ssh: 
     publicKeyName: #use existing EC2 key 

     - name: ng-mixed 
     minSize: 3 
     maxSize: 5 
     instancesDistribution: 
         maxPrice: 0.2 
         instanceTypes: ["t2.small", "t3.small"] 
         onDemandBaseCapacity: 0 
         onDemandPercentageAboveBaseCapacity: 50 
     ssh: 
         publicKeyName: #use existing EC2 key 

Step 2: Run the below command to create ng-mixed node group and after that check in the ec2 instances.
eksctl create nodegroup --config-file=nodegroup.yml --include='ng-mixed'

Step 3: Run the below command to delete ng-mixed node group
eksctl delete nodegroup --config-file=nodegroup.yml --include=ng-mixed --approve

AWS Containers - EKS Lab Setup (using Region Virginia (us-east-1))




For Lab point of view we will setup the environment as per below diagram





Step 1:- Create an IAM user and EKS Role
  • Create the user with IAM with console and programmatic and download security credentials with security access id and Access key
  • Permission point of view provide EKSFullAccess(There are some set of policies you need to add) and other permission as per the requirement to deal EKS with other services
  • Create IAM Role for EKS
  • EKS (Allows EKS to manage clusters on your behalf.):- Role name :- AWSServiceRoleForAmazonEKS
  • EKS - Cluster AWSClusterRoleForAmazonEKS

Step 2:- Create the SSH key pair

  • Create SSH key value pair (I am creating a key pair as vdevops)

Step 3:- Setup Command line Tools
  • Install awscli on Ubuntu Ec2 Instance
apt install unzip -y
curl "https://awscli.amazonaws.com/awscli-exe-linux-x86_64.zip" -o "awscliv2.zip"
unzip awscliv2.zip
sudo ./aws/install
export PATH=/usr/local/bin:$PATH
aws --version
aws configure (To confiure aws credential with region=us-east-1)

  • Install and setup eksctl
curl --silent --location "https://github.com/weaveworks/eksctl/releases/latest/download/eksctl_$(uname -s)_amd64.tar.gz" | tar xz -C /tmp
sudo mv /tmp/eksctl /usr/local/bin
eksctl version

  • Install and setup kubectl
curl -LO "https://dl.k8s.io/release/$(curl -L -s https://dl.k8s.io/release/stable.txt)/bin/linux/amd64/kubectl"
sudo install -o root -g root -m 0755 kubectl /usr/local/bin/kubectl
kubectl version --client

Step 4:- Create first EKS Cluster using eksctl

Create a yaml file to create EKS Cluster ( I have given file name as eks.yaml)
apiVersion: eksctl.io/v1
alpha5 
    kind: ClusterConfig

    metadata: 
        name: EKS-raman-cluster 
        region: us-east-1

    nodeGroups: 
        - name: ng-1 
        instanceType: t2.small 
        desiredCapacity: 3
        volumeSize: 10 
        ssh: 
            publicKeyName: #use existing EC2 key  

Step 5:- Run below commands w.r.t eksctl

# Find the available options for eksctl create cluster command 
eksctl create cluster --help 

# create cluster by using yaml config file (it will take 15-20 mins to create cluster ) 
eksctl create cluster -f eks.yaml 

# Post cluster check 
kubectl get nodes 

# check there must be a /root/.kube/config file which refers to EKS Cluster 

# get cluster 
eksctl get cluster 

# get node group details of the cluster 
eksctl get nodegroup --cluster EKS-raman-cluster



AWS Containers - EKS introduction




EKS
Amazon Elastic Kubernetes Service (EKS) is a managed Kubernetes service that makes it easy for you to run Kubernetes on AWS and on-premises.

Amazon EKS automatically manages the availability and scalability of the Kubernetes control plane.

EKS lets you run your Kubernetes applications on both Amazon EC2 and AWS Fargate.

Amazon EKS supports using Elastic Load Balancing including Application Load Balancer (ALB), Network Load Balancer (NLB), and Classic Load Balancer.

Amazon EKS is integrated with AWS CloudTrail to provide visibility and audit history of EKS management operations.

Deploy applications with EKS in the cloud.

EXTRA INFOS: AWS - Installing AWSCLI on your local ubuntu system

Setup Command line Tools

  • Install awscli on Ubuntu Ec2 Instance
    apt install unzip -y
    curl "https://awscli.amazonaws.com/awscli-exe-linux-x86_64.zip" -o "awscliv2.zip"
    unzip awscliv2.zip
    sudo ./aws/install
    export PATH=/usr/local/bin:$PATH
    aws --version
    aws configure (To configure aws credential with region=us-east-1)

AWS Compute - Transit Gateway

 


Transit Gateway is 1 to 1 relationship with VPC.

1 VPC can only have 1 Transit Gateway


1. Create Transit Gateway:

Step 1: Remove the peering connection from Route Tables and also delete the peering connection

Step 2: Select Transit Gateway From VPC left panel option.

Step 3: Click on Create Transit Gateway.

Step 4: Define the following properties

  • Name:  irfan-tsgw
  • Rest of the properties are same
  • Click on Create Transit Gateway
2. Create Transit Gateway Attachment:

Step 1: Create the transit gateway attachments by selecting Transit Gateway Attachment link.

Step 2: Click on Create Transit Gateway button.

Step 3: Provide following details.

  • Name: irfan-tsgwattch
  • Transit Gateway:  irfan-tsgw
  • Attachment Type: VPC
  • select VPC : irfan-vpc-pn-1
  • Click on Create Transit Gateway attachment.

Step 4: Repeat Step 3 for irfan-vpc-pn-2

Step 5: Update Route tables of each VPC by adding CIDR range of other VPCs and connection type should be Transit Gateway.

Step 6: Create EC2 instances in each VPC and you will find that they can communicate to each other with a private network.


AWS Compute - Peering Connections


VPC peering is non-transitive, means if vpc A advertises it's route to vpc B, it is exclusive. thus if there is a vpc C, and it request the info of vpc A route from vpc B, it is not possible to do so. (cause that's called a hub - all connected with vpc B as middle man).

so in order for all of them to be connected, they can try to do a fully meshed vpc peering like the pic below:



now this looks simple because it only involves 3 vpcs, what if it scales up? let's say 10 vpcs? how many peer networks need to be established?? the answer is using the formula: n x (n -1 /2). so for the case of 10 vpcs: 10 x (10-1/2) = 10 x 4.5 = 45. total of 45 networks need to be established! so if 100 vpcs, it would not be able to scale gracefully.


So there is one more solution called: Hub and Spoke but it has it's limitations such that only the hub can be connected to all spoke but the spokes cannot connect to other spokes. this is useful in business terms. See pic below and see if you can figure it out:



but let's say you're a company, and in your company, there are different departments, and they want to talk to each other, so you use CloudHub or Transit Gateway (or in early days, they call it route reflector that they use in IBGP to break the rules).

Difference between CloudHub and Transit Gateway is that CloudHub uses VPN (vpn is not private) but Transit Gateway uses private lines or combo of private line and VPN. both of these systems can break the rules of non-transitive peering. 



For Peer Connections using 1 account (by right must between 2 different accounts, but for example purpose, we will use 1 account only)

Step 1: Create 2 VPC myvpc-1 (11.0.0.0/16) and myvpc-2 (10.0.0.0/16) and its required components like subnet, Route Tables, IGW etc. (You can create VPC by using VPC with all its components option).

Step 2: Create an EC2 instance in each VPC and provide SG as all traffic and public IP addresses.

Step 3: Connect to any EC2 instance and try to ping the private IP address of other EC2 instances. You will not be able to ping because both instances are in different VPC.

Step 4: Select Peering connection using VPC left panel's options.

Step 5: Click on Create Peering connection

Step 6: Provide below configuration for your peering connection

  • Name: myvpc-peer-to-yourvpc
  • Requestor: Your VPC
  • Acceptor: Other VPC, in real life, you will need their VPC ID and some other IDs

Step 7: Select Action and Click on Accept

Step 8: Update Route tables of each VPC by adding source as other VPC CIDR Range and connection type is peering connection.

Step 9: Now EC2 instances can ping to each other


Wednesday, March 23, 2022

IBM Capstone



1. Take up a java based containerised application and create the CI CD pipeline which includes quality scan, security scan, etc. (Estimate 2 days)

· Any sample java ok to use for this

we will be using sample java created by maven archetype

· Assume Gitlab Pipeline
we will be having 3 branches for 3 developers, which are layered by a release branch before merging into main branch.
Assuming 1 developer has the sample java, he/she will merge request his/her code to release, then a team from release will merge into main branch.

· Pipeline build and test command from your sample java project
upon merging the code to main branch, the code will automatically be placed in the CI pipeline in GitLab.
the code will be built by maven into an executable .jar file
and at the same time will have project analyzation via sonarQube

· Pipeline Pass Criteria Controls:
o Code Coverage %,
o Vulnerability control: No high and critical
sonarQube (localhost:9000) will provide this information

· Where to store the artifacts?

· What it takes for Image Pass Criteria to be implemented
in the build stage, we will dockerise the built code into a docker image via a Dockerfile.

o How can the pipeline include CVE for image
we will scan the docker image with docker scan-snyk / trivy
o How to distribute to registry (any registry that you are familiar with, DockerHub or GitLab registry) in pipeline
then we will push the docker image into hub.docker

· Kubernetes with structure that can access from public traffic

o you need to include any Kubernetes CRD that is required for that image to be able to access from public



o Assume the Cluster is ready for usage










stages: - build - test - deploy build: stage: build tags: - localrunner - localshell script: - mvn archetype:generate maven-build: stage: build tags: - localrunner - localshell script: - cd /home/vagrant/mvnrepo - sudo mvn clean package artifacts: paths: - target/surefire-reports/TEST-*.xml reports: junit: - target/surefire-reports/TEST-*.xml test: stage: test tags: - localrunner - localshell script: - sudo ls /home/vagrant/mvnrepo/target/*.jar newtest: stage: test tags: - localrunner - localshell script: - sudo touch /home/vagrant/mvnrepo/passtest deploy: stage: deploy tags: - localrunner - localshell script: - cd /home/vagrant/mvnrepo - sudo java -cp target/myproj-1.0-SNAPSHOT.jar com.raman.App







mkdir -p ~/.docker/cli-plugins


curl https://github.com/docker/scan-cli-plugin/releases/latest/download/docker-scan_linux_amd64 -L -s -S -o ~/.docker/cli-plugins/docker-scan


chmod +x ~/.docker/cli-plugins/docker-scan








# appjava-dep.yaml apiVersion: apps/v1 kind: Deployment metadata: name: appjava-dep labels: app: app-java spec: replicas: 2 template: metadata: labels: app: app-java spec: containers: - name: capstone-container image: ifanrahman/capstone-image ports: - containerPort: 80 selector: matchLabels: app: app-java

apiVersion: v1 kind: Service metadata: name: appjava-np labels: app: appjava-app spec: selector: app: appjava-app type: NodePort ports: - nodePort: 80 #clusterIP (THIS ONE NEED TO CHECK ON YOUR VAGRANTFILE CONFIG WHAT GUEST PORT) port: 80 #service port targetPort: 80 #container port


Tuesday, March 22, 2022

AWS Management & Governance - CloudFormation

 


Cloudform Templates: https://docs.aws.amazon.com/AWSCloudFormation/latest/UserGuide/template-reference.html

SUMMARY:

  • Example 1: Create an EC2 instance using CloudFormation Template.
  • Example 2: Create two resources (EC2 instance and S3 bucket). Follow the same steps are mentioned in Example1 for execution.
  • Example 3: Create EC2 instance and attach a Security group with EC2 instance.
  • Example 4: Create an IAM Group and Add a user to that group.
  • Example 5: Serverless End to End Web application deployment using Beanstalk

Prerequisite:

  • Download and Install VSCode
  • Add CloudFormation Linter Extension to VSCode  
  • Python latest version is to be installed on your system
  • A default VPC for the users in the region must have been configured              


Example 1: Create an EC2 instance using CloudFormation Template.

Step 1 Open a file .yaml is visual studio code.

Step 2: Add Cloudformation Linter Extension to your VSCode

Step 3: Run the following commands in the terminal

           pip install cfn-lint.

           pip install pydot

Step 4: Create a new file with extension .yaml or .yml (main.yml)

Step 5: Write the below sample code to create an EC2 instance using the Cloudformation template (change the ImageId and KeyName accordingly)

Resources:
  MyEC2Instance:
   Type: AWS::EC2::Instance
   Properties:
     ImageId: ami-04893cdb768d0f9ee
     InstanceType: t2.micro
     KeyName: IrfanSydney
     Tags:
       - Key: Name
         Value: irfan-ec2-viacloudform

Step 6: Go to Cloudformation Service.

Step 7: Click on Create Stack button.

  • Select option Template is ready
  • Select Upload a Template file
  • Choose your file

Step 8: Click on Next

Step 9: Provide Stack name and Click on Next

Step 10: Review and Create the stack.

Step 11: Verify the Events and once All the resources (EC2 instance) get created then check if the EC2 instance got created or not.

Experiment: Delete Stack and Check the EC2 instance also get deleted.

Ans: yes it is deleted also.


Example 2: Create two resources (EC2 instance and S3 bucket). Follow the same steps are mentioned in Example1 for execution.

Resources:
  MyEC2Instance:
   Type: AWS::EC2::Instance
   Properties:
     ImageId: ami-04893cdb768d0f9ee
     InstanceType: t2.micro
     KeyName: devops
     Tags:
       - Key: Name
         Value: Ec2-Demo
  S3Bucket:
    Type: 'AWS::S3::Bucket'
    DeletionPolicy: Retain
    Properties:
      BucketName: mumbairegionmy      

in example2, NEED TO REMEMBER THAT BUCKET NAME CANNOT HAVE UPPERCASE. ALL MUST LOWERCASE.

BUT when deleting the cloudformation, S3 bucket is not deleted!!


Example 3: Create EC2 instance and attach a Security group with EC2 instance.

Resources:
  MyEC2Instance:
    Type: AWS::EC2::Instance
    Properties:
      ImageId: ami-0916f5ee07e7b15d6
      InstanceType: t2.micro
      KeyName: IrfanSydney
      Tags:
        - Key: Name
          Value: irfan-EC2-viaCloudformation
      SecurityGroupIds:
        - sg-04fea68279857c128

if you have deleted the default VPC, then you will need to create a new security group cause if not the networks of the old security groups are different.

if you delete the cloudform for ec2 and security group, the ec2 will be deleted but security group will not.

Example 4: Create an IAM Group and Add a user to that group.

Resources:
  iamGroup:
    Type: AWS::IAM::Group
    Properties:
      GroupName: irfan-groupviacloudform
  iamUser:
    Type: AWS::IAM::User
    Properties:
      UserName: irfan-user-viacloudform
      Path: /
      Groups:
        - irfan-groupviacloudform
      LoginProfile:
        Password: <addyourpassword>
        PasswordResetRequired: false

if you delete the cloudform for user and groupuser, the user and groupuser also gets deleted!!


Example 5: Serverless End to End Web application deployment using Beanstalk via Cloudform

AWSTemplateFormatVersion: '2010-09-09'
Resources:
  sampleApplication:
    Type: AWS::ElasticBeanstalk::Application
    Properties:
      Description: AWS Elastic Beanstalk Sample Application
  sampleApplicationVersion:
    Type: AWS::ElasticBeanstalk::ApplicationVersion
    Properties:
      ApplicationName:
        Ref: sampleApplication
      Description: AWS ElasticBeanstalk Sample Application Version
      SourceBundle:
        S3Bucket: !Sub "elasticbeanstalk-samples-${AWS::Region}"
        S3Key: php-newsample-app.zip
  sampleConfigurationTemplate:
    Type: AWS::ElasticBeanstalk::ConfigurationTemplate
    Properties:
      ApplicationName:
        Ref: sampleApplication
      Description: AWS ElasticBeanstalk Sample Configuration Template
      OptionSettings:
      - Namespace: aws:autoscaling:asg
        OptionName: MinSize
        Value: '2'
      - Namespace: aws:autoscaling:asg
        OptionName: MaxSize
        Value: '6'
      - Namespace: aws:elasticbeanstalk:environment
        OptionName: EnvironmentType
        Value: LoadBalanced
      - Namespace: aws:autoscaling:launchconfiguration
        OptionName: IamInstanceProfile
        Value: !Ref MyInstanceProfile        
      SolutionStackName: 64bit Amazon Linux 2 v3.3.11 running PHP 8.0
  sampleEnvironment:
    Type: AWS::ElasticBeanstalk::Environment
    Properties:
      ApplicationName:
        Ref: sampleApplication
      Description: AWS ElasticBeanstalk Sample Environment
      TemplateName:
        Ref: sampleConfigurationTemplate
      VersionLabel:
        Ref: sampleApplicationVersion
  MyInstanceRole:
    Type: AWS::IAM::Role
    Properties:
      AssumeRolePolicyDocument:
        Version: 2012-10-17
        Statement:
          - Effect: Allow
            Principal:
              Service:
                - ec2.amazonaws.com
            Action:
              - sts:AssumeRole
      Description: Beanstalk EC2 role
      ManagedPolicyArns:
        - arn:aws:iam::aws:policy/AWSElasticBeanstalkWebTier
        - arn:aws:iam::aws:policy/AWSElasticBeanstalkMulticontainerDocker
        - arn:aws:iam::aws:policy/AWSElasticBeanstalkWorkerTier
  MyInstanceProfile:
    Type: AWS::IAM::InstanceProfile
    Properties:
      Roles:
        - !Ref MyInstanceRole

Check the BeanStalk Env and application these should be created and you will be able to access the application on browser.


When you delete this cloudformation, the EC2 also got deleted!

AWS Compute - Elastic Beanstalk


Deploy Application using Serverless end to end service Beanstalk


Step 1: Select Elastic Beanstalk service.

Step 2: Click on Create Application

  • Application Name: MyApp
  • Platform: PHP
  • Application Code: Sample Code
  • Click on Create Application button

Step 3: Use Application URL to access the webapp


This will create all the necessary things e.g EC2 instance, security group, database.


Step 4: to delete the elastic beanstalk, you will need to delete the EC2 and everything it creates first.

Fluentd

Open-source log data collector > why logs? - for compliance (auditing, company, business) - for security (transparency, monitoring, admin...