{"componentChunkName":"component---src-templates-blog-js","path":"/ctf/aws-formation/tp1-cicd","result":{"data":{"markdownRemark":{"html":"<h2>1 -  What is CI CD</h2>\n<ul>\n<li>CodeCommit : source control service</li>\n<li>CodeBuild : compiling source codes, runs test and produces packages ready to deploy</li>\n<li>CodeDeploy : Automates code deployment to any instance (as EC2)</li>\n<li>CodePipeline = CodeCommit + CodeBuild + CodeDeploy</li>\n</ul>\n<h3>to remember</h3>\n<ul>\n<li>Continuous Integration = CodeCommit</li>\n<li>Continuous Delivery = CodeBuild + CodeDeploy</li>\n<li>Continuous Deployment : CodePipeline</li>\n</ul>\n<h2>2 - CodeCommit 101</h2>\n<h3>to remember</h3>\n<ul>\n<li>Centralized Code Repository</li>\n<li>Enables Collaboration</li>\n<li>Version Control</li>\n</ul>\n<h2>3 -  CodeCommit Lab</h2>\n<h3>ToDo</h3>\n<ol>\n<li>Developer Tools</li>\n<li>CodeCommit</li>\n<li><strong>Create a repository</strong></li>\n<li>Create branch</li>\n<li>Create a commit</li>\n<li>Create a pull request</li>\n</ol>\n<p>If the branch is out update, we have to clone the master branch before to push on it</p>\n<h2>4 - CodeDeploy 101</h2>\n<p>Automated Deployment works with :</p>\n<ul>\n<li>EC2 instances</li>\n<li>on-premises</li>\n<li>lambda</li>\n</ul>\n<p>Instance runs on <strong>Elastic Run Balancment</strong></p>\n<p>2 deployment approaches :</p>\n<ol>\n<li>In-Place : the application is stopped on each instance = <em>Rolling Instance</em> :</li>\n<li>1 elastic run balancment + 3 instances </li>\n<li>so the capacity will be reduced</li>\n<li>new version = Revision (= virgin)</li>\n<li>you can NOT rollback quickly</li>\n<li>first deploying</li>\n<li>fees : +</li>\n<li>Blue (active deployment) / Green (the new release) :</li>\n<li>1 elastic run balancment + 2 group of 3 instances</li>\n<li>switch between group of instance</li>\n<li>no reduces of capacity</li>\n<li>you can rollback quickly</li>\n<li>after first deployment</li>\n<li>fees : ++</li>\n<li><strong>safest option</strong></li>\n</ol>\n<h2>5 - Advanced codedeploy the AppSpec File</h2>\n<p><strong>AppSpec File</strong> : configuration files defining the parameters used during a CodeDeploy deployment</p>\n<p>Le fichier Appspec est un fichier spécifique à CodeDeploy. Ce fichier permet d'orchestrer les actions à mener sur une machine. Il est sous  format YAML ou JSON et se place à <strong>la racine du repository GitHub</strong> de notre WordPress.</p>\n<p>Ce fichier est nécessaire pour :</p>\n<ul>\n<li>mapper les fichiers applicatifs avec leur destination sur l'instance</li>\n<li>gérer les droits des fichiers applicatifs</li>\n<li>spécifier des scripts à exécuter durant le cycle de vie du déploiement.</li>\n</ul>\n<h3>File structure</h3>\n<ul>\n<li>version (allowed value is 0.0)</li>\n<li>OS</li>\n<li>files : location</li>\n<li>hooks : life cylce event hooks (have a specific <strong>run order</strong>)</li>\n</ul>\n<p><img src=\"/assets/TP2-CICD-appspec.png\" alt=\"appspec\" title=\"appspec\"></p>\n<h3>step</h3>\n<p>root folder contains : </p>\n<ul>\n<li>scripts (launch in the appspec.yml indicates in the hook :  (install<em>dependencies.sh or start</em>server.sh or stop_server.sh) )</li>\n<li>Config</li>\n<li>Source (index.html)</li>\n<li>appspec.yml (root position of the yml file)</li>\n</ul>\n<h2>6 - CodeDeploy Lifecylce Event Hooks</h2>\n<h3>Run Order - Phase</h3>\n<ol>\n<li><strong>De-registering</strong> instances from a load balancer</li>\n<li>Before Block Traffic</li>\n<li>Block Traffic</li>\n<li>After Block Traffic</li>\n<li><strong>Installation</strong> : The real nuts &#x26; bolts of the appllication deployment</li>\n<li>application stop</li>\n<li>Download Bundle : CodeDeploy agent copies the application revision files to a <em>temporary</em> location</li>\n<li>BeforeInstall : Pre install script (as backing up the current version or decrypting files)</li>\n<li>Install : Copy application revision files to* final* location</li>\n<li>AfterInstall : Post install scripts e.g. configuration</li>\n<li>ApplicationStart</li>\n<li>ValidateService (test)</li>\n<li><strong>Re-registrering</strong> with the load balancer</li>\n<li>Before Allow Traffic</li>\n<li>Allow Traffic</li>\n<li>After Allow Traffic</li>\n</ol>\n<p><a href=\"https://docs.aws.amazon.com/fr_fr/codedeploy/latest/userguide/deployment-steps-server.html#deployment-steps-components-server\">https://docs.aws.amazon.com/fr_fr/codedeploy/latest/userguide/deployment-steps-server.html#deployment-steps-components-server</a></p>\n<p>CodeDeploy sont les suivantes:</p>\n<ol>\n<li>On crée une application CodeDeploy</li>\n<li>On cible les instances sur lesquelles on va déployer : le groupe de déploiement</li>\n<li>On spécifie la configuration du déploiement</li>\n<li>On envoie une révision du code à CodeDeploy</li>\n<li>CodeDeploy la déploie</li>\n<li>On vérifie le résultat</li>\n<li>Si besoin on redéploie</li>\n</ol>\n<h2>7 - CodeDeploy Lab</h2>\n<h3>ToDo</h3>\n<ol>\n<li>Security, Identity &#x26; Compliance</li>\n<li>IAM</li>\n<li>Create a role from S3Full access policy</li>\n<li>Create a role from AWSCodeDeployRole : Allow it to call AWS services, allowing :</li>\n<li>AutoScaling</li>\n<li>Describe instances and terminates instances</li>\n<li>cloudwatch </li>\n<li>tags</li>\n<li>registering and deristering with our load balancer</li>\n<li>Services - Compute - EC2 IAM Linux</li>\n<li>noneed to define a subnet</li>\n<li>auto assign public ip</li>\n<li>add tags to help codeploy to use this tags to identify the instance to deploy</li>\n<li>configure security group : SSH &#x26; HTTP</li>\n<li>choose a key pair</li>\n<li>Connect to ec2-user@<ip-address-of-my-instance></li>\n<li>\n<p>on the instance. </p>\n<ul>\n<li>wget htps://aws-codedeploy-eu-wet-2.s3.amazoaws.com/latest/install</li>\n<li>sudo service codedeploy agent status</li>\n</ul>\n</li>\n<li>connect the local machine to code deploy from the local machine</li>\n<li>\n<p>on aws console :</p>\n<ul>\n<li>add user and save its access key ID and value (programmatic access)</li>\n</ul>\n</li>\n<li>\n<p>on the local machine :</p>\n<ul>\n<li>$ aws configure</li>\n</ul>\n</li>\n<li>Upload in a bucket the config files (appspec.yml : application bundle) to give the possibility to CodeDeploy to Access them</li>\n<li>AWS console -  S3 - Storage - bucket</li>\n</ol>\n<pre><code>2.$  aws deploy create-application --application-nam mywebapp\n</code></pre>\n<ol start=\"9\">\n<li>Developper Tools</li>\n<li>CodeDeploy</li>\n<li>Application - mywebapp</li>\n<li>deployment group - create :\n1. envirobment configuration : Amazon EC2 instances\n2. setting : AllAtOnce, halfAtOnce\n3. Use or not the loadbalancer</li>\n<li>Application lifecycle event failure</li>\n<li>Rollback configuration</li>\n</ol>\n<h2>8 - CodePipeline</h2>\n<h3>Roles</h3>\n<p><strong>A fully managed CI/CD service</strong> :</p>\n<ol>\n<li>Triger a pipelin every time there is a change to our code</li>\n<li>Aitomated Release Process</li>\n<li>integrates with AWS tools :</li>\n<li>CodeCommit, CodeBluid, CodeDeploy, GitHub, Jenkins, Elastiks (containers managers)... </li>\n</ol>\n<h3>CodePipeline Workflow</h3>\n<ol>\n<li>CodePipeline (workflow defined)</li>\n<li>CodeCommit (new code appears)</li>\n<li>CodeBuild (testes)</li>\n<li>CodeDeploy (application deployed)</li>\n</ol>\n<h3>to remember</h3>\n<p><img src=\"/assets/TP2-CICD-CodePipeline.png\" alt=\"CodePipeline1\" title=\"codepipeline1\"></p>\n<h2>9 - CodePipeline lab</h2>\n<h3>steps</h3>\n<ol>\n<li>Cloud formation to create an EC2 instance</li>\n<li>Upload a version 1 to S3 bucket</li>\n<li>Deploy EC2 instance using codeDeploy</li>\n<li>Code Pipeline : a managed trigger to deploy our version 2</li>\n<li>Cloud Watch : : a automaticaly trigger  to deploy our version 3</li>\n</ol>\n<p><img src=\"TP2-CICD-CodePipelineLab.png\" alt=\"CodePipeline2\" title=\"codepipeline2\"></p>\n<h3>Origin folder and files</h3>\n<p>CF.txt : CloudFormation commands : laucnh an EC2 instance as on the AWS console</p>\n<p>CF.json : tag our instance to identify xith code deploys, asosicate an SSH key pair name, set up a security group, mapping in at least a region</p>\n<h3>steps</h3>\n<h4>1sr deployment</h4>\n<ol>\n<li>creation of the bucket using CloudFormation : </li>\n<li>upload the CF_template .json files to your own bucket</li>\n<li>run the CF.txt files</li>\n<li>before :</li>\n<li>indicates bucket name</li>\n<li>indicates key pair name </li>\n<li>create policy to grant new right to the user</li>\n<li>add the app.zip to the bucket</li>\n<li>verify that the cloud Formation wtack has completed using :</li>\n<li>$ awscloudformation describe-stacks --stack-name</li>\n<li>Log into you instance and check that the codeploy agent has correctly installed :</li>\n<li>laucnh EC2 instance and copy its IPV4 IP</li>\n<li>ssh i- keypair.pem ec2-user@<key-ip></li>\n<li>sudo service codedeploy-agent status</li>\n<li>CodeDeploy</li>\n<li>Deploy Group new</li>\n<li>Find the instance thanks to its instance</li>\n</ol>\n<p>step with Code Pipeline with manually upload :</p>\n<ol>\n<li>Choose pipeline settinfs</li>\n<li>Add source stage (where our application S3 object key : app.zip is locataed)</li>\n<li>Add build state (providing build artificat details like OS, output files names : CodeBuild or Jenkins)</li>\n<li>Add deploy stage (deploy provider, region, application name, deployment group)</li>\n</ol>\n<p>step with Code Pipeline with triggered codeDeploy (automatic deployment)</p>\n<ol>\n<li>upload the app.zip </li>\n</ol>\n<h2>10 - IAM - Lab</h2>\n<p><img src=\"IAM-1.png\" alt=\"iam1\" title=\"iam1\"></p>\n<p>.JSON :</p>\n<pre><code class=\"language-json\">{\n  \"Version :\" : \"2012-10-37\",\n  \"Statement\" [\n    {\n      \"Effect\" : \"Allow\",\n      \"Action\" : \"*\",\n      \"Resource\" : \"*\"\n    }\n  ]\n}\n</code></pre>\n<h3>to remember</h3>\n<ol>\n<li>Roles are more secure thant storing your access key and secret access key on individual EC2 instances</li>\n<li>Roels are easier to manage</li>\n<li>Roelse can be assigner to an EC2 instance after it is created using both AWS console and command line</li>\n<li>Roles are universal (any region)</li>\n</ol>\n<h2>11-  Using BootStrap Script - Lab</h2>\n<p>Way to automatisating AWS deployment</p>\n<h3>ToDo</h3>\n<p>1.S3 bucket using our bootstrap script</p>\n<ol start=\"2\">\n<li>\n<p>Add in Advanced details at the configure Instance details</p>\n<pre><code class=\"language-bash\">#!/bin/bash\nyum update -y\nyum install httpd -y\nservice httpd start\nchkconfig httpd on\ncd /var/www/html\necho \"Hello\"\naws s3 mb s3 \naws s3 cp index\n</code></pre>\n</li>\n</ol>\n<h2>12 - Instance MetaData</h2>\n<p>curl <a href=\"http://123.123.132/latest/meta-data\">http://123.123.132/latest/meta-data</a>\n\\ > bootstrap.txt</p>\n<p><img src=\"Instance%20MetaData.png\"></p>\n<p>curl <a href=\"http://123.123.132/latest/user-data\">http://123.123.132/latest/user-data</a>\n\\ > ip_adress.txt</p>\n<h2>EC2 vs Lambda</h2>\n<p><a href=\"https://www.simform.com/aws-lambda-vs-ec2/\">https://www.simform.com/aws-lambda-vs-ec2/</a></p>\n<h3>EC2 = Elastic</h3>\n<p>AppSpec file : YAML only</p>\n<p>Amazon Elastic Compute Cloud (EC2) est un service d'infrastructure de cloud virtuel proposé par AWS. Il fournit des ressources informatiques à la demande grâce auxquelles vous pouvez créer de puissants serveurs dans le nuage.</p>\n<p>L'ensemble du matériel de l'EC2 est fragmenté en de multiples ressources qui sont offertes sous la forme d'instances évolutives en termes de mémoire de calcul et de puissance de traitement.</p>\n<p>Il vous offre également la possibilité d'héberger votre application sur plusieurs plateformes avec une sécurité renforcée pour une architecture multi-modèles et multi-locataires. Ces instances peuvent être accessibles par HTTP ou HTTPS (API), ce qui permet aux développeurs de créer des applications comme s'il s'agissait d'une infrastructure sur site.</p>\n<p>Avec Amazon EC2, vous avez la possibilité d'approvisionner des machines virtuelles selon les besoins de vos applications. Cette possibilité est offerte dans le cadre d'un modèle d'abonnement basé sur l'utilité, où l'utilisateur est facturé en fonction de sa consommation de ressources.</p>\n<h3>AWS Lambda</h3>\n<p>AppSpec file : YAML and JSON</p>\n<p>AWS Lambda est une ressource de cloud computing à la demande proposée en termes de fonction-as-a-service par AWS. Au fil du temps, </p>\n<p>La principale différence entre AWS Lambda et EC2 (ressources basées sur des serveurs virtuels) réside dans la responsabilité du provisionnement et des cas d'utilisation, pour n'en citer que quelques-uns. La tarification d'AWS Lambda est également l'un des principaux facteurs.</p>\n<p>Avant l'émergence de solutions agiles comme AWS Lambda, les équipes opérationnelles devaient allouer les ressources en fonction des prévisions. Elles devaient s'assurer que les besoins en ordinateurs et en mémoire ne dépassaient pas les limites que leur système pouvait supporter.</p>\n<p>Avec des ressources informatiques comme AWS Lambda, les ressources informatiques peuvent s'adapter et diminuer automatiquement en fonction des demandes en temps réel. Actuellement, AWS Lambda prend en charge plusieurs langues et peut être utilisé dans une application de plusieurs manières ou en tant que service.</p>\n<p>L'architecture des applications construites à l'aide de fonctions comme AWS Lambda est communément appelée architecture sans serveur. </p>\n<h3>Which one to use</h3>\n<p>If you’re wasting your compute resources due to unpredictable traffic for your application but still want a scalable and cost friendly solution, AWS Lambda is for you. When not to use AWS Lambda? When you want to do complex processing and your process can’t be executed in the limited execution time.Or maybe you want to run a complex application which has consistent traffic and want to operate in a tried and tested deployment environment, EC2 if for you. The only drawbacks are a complex setup environment and provisioning of servers.The result- For either AWS Lambda vs EC2 or vice versa, both operate for a highly specific use case, however, one wasn’t sufficing the need which necessitated the invention of another.Until then, let’s make the most of each of the services. If you’ve hands-on experience with either EC2 or Lambda or both, I’d love to hear from you.</p>","frontmatter":{"date":"July 31, 2020","path":"ctf/aws-formation/tp1-cicd","title":"TP2 - CICD","tags":["cloud","ec2","aws"],"categorie":"ctf","thumbnail":"/assets/alex-machado-80sv993luki-unsplash.jpg"},"fields":{"readingTime":{"text":"10 min read"}}},"file":{"childImageSharp":{"fluid":{"base64":"data:image/jpeg;base64,/9j/2wBDABALDA4MChAODQ4SERATGCgaGBYWGDEjJR0oOjM9PDkzODdASFxOQERXRTc4UG1RV19iZ2hnPk1xeXBkeFxlZ2P/2wBDARESEhgVGC8aGi9jQjhCY2NjY2NjY2NjY2NjY2NjY2NjY2NjY2NjY2NjY2NjY2NjY2NjY2NjY2NjY2NjY2NjY2P/wgARCAANABQDASIAAhEBAxEB/8QAFwAAAwEAAAAAAAAAAAAAAAAAAAMEBf/EABUBAQEAAAAAAAAAAAAAAAAAAAED/9oADAMBAAIQAxAAAAGFz11jKaIn/8QAGhAAAgMBAQAAAAAAAAAAAAAAAAECERMSMf/aAAgBAQABBQLm3gxwaJTxe1i8/8QAGBEAAgMAAAAAAAAAAAAAAAAAAAECElH/2gAIAQMBAT8BUdKn/8QAFhEBAQEAAAAAAAAAAAAAAAAAABEB/9oACAECAQE/Abqv/8QAGhAAAQUBAAAAAAAAAAAAAAAAAQACEBESIv/aAAgBAQAGPwJckOjObVBtR//EABwQAQACAgMBAAAAAAAAAAAAAAEAETFBIWFxkf/aAAgBAQABPyEVB9ih2jUSxfkFQDkWX4Ju5grU/9oADAMBAAIAAwAAABDjD//EABYRAQEBAAAAAAAAAAAAAAAAAAEAIf/aAAgBAwEBPxAA1M//xAAWEQEBAQAAAAAAAAAAAAAAAAABIRD/2gAIAQIBAT8QWYTP/8QAGhABAQEAAwEAAAAAAAAAAAAAAREAIUFxwf/aAAgBAQABPxAYkFlcFzRnCFCH3zCCggiKI5gk6hL1lpwEhs0zEABv/9k=","aspectRatio":1.4970059880239521,"src":"/static/11cdcb302d032fa2db3a46428a8f74c9/a7715/alex-machado-80sv993luki-unsplash.jpg","srcSet":"/static/11cdcb302d032fa2db3a46428a8f74c9/8f7df/alex-machado-80sv993luki-unsplash.jpg 250w,\n/static/11cdcb302d032fa2db3a46428a8f74c9/0f3a1/alex-machado-80sv993luki-unsplash.jpg 500w,\n/static/11cdcb302d032fa2db3a46428a8f74c9/a7715/alex-machado-80sv993luki-unsplash.jpg 1000w,\n/static/11cdcb302d032fa2db3a46428a8f74c9/37d86/alex-machado-80sv993luki-unsplash.jpg 1500w,\n/static/11cdcb302d032fa2db3a46428a8f74c9/a41d1/alex-machado-80sv993luki-unsplash.jpg 2000w,\n/static/11cdcb302d032fa2db3a46428a8f74c9/6a059/alex-machado-80sv993luki-unsplash.jpg 6000w","sizes":"(max-width: 1000px) 100vw, 1000px"}}}},"pageContext":{"slug":"ctf/aws-formation/tp1-cicd","featuredImage":"alex-machado-80sv993luki-unsplash.jpg"}}}