{"id":154,"date":"2023-04-02T22:08:38","date_gmt":"2023-04-02T20:08:38","guid":{"rendered":"https:\/\/www.mutareb.com\/?p=154"},"modified":"2023-04-02T22:10:35","modified_gmt":"2023-04-02T20:10:35","slug":"testing-out-aws-elastic-beanstalk","status":"publish","type":"post","link":"https:\/\/www.mutareb.com\/index.php\/2023\/04\/02\/testing-out-aws-elastic-beanstalk\/","title":{"rendered":"Testing out AWS Elastic Beanstalk"},"content":{"rendered":"\n<p>Elastic Beanstalk is the PaaS component of AWS, it will automatically handle the details of capacity provisioning, load balancing, scaling, and application health monitoring.<\/p>\n\n\n\n<p>We will go to AWS Elastic Beanstalk Documentation, look for &#8220;Install the EB CLI&#8221; to install the eb cli on the cloud9 environment. At the time of writing it was just cloning the Github repo, running the python installation script and adding &#8216;eb&#8217; to path:<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>git clone https:\/\/github.com\/aws\/aws-elastic-beanstalk-cli-setup.git\npython .\/aws-elastic-beanstalk-cli-setup\/scripts\/ebcli_installer.py\necho 'export PATH=\"\/home\/ec2-user\/.ebcli-virtual-env\/executables:$PATH\"' >> ~\/.bash_profile &amp;&amp; source ~\/.bash_profile<\/code><\/pre>\n\n\n\n<p>To test it we will create a simple flask page, but let&#8217;s prepare the environment first:<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>mkdir eb-flask\ncd eb-flask\npython3 -m venv virt\nsource virt\/bin\/activate\npip install flask\npip freeze > requirements.txt<\/code><\/pre>\n\n\n\n<p>Now to add the following simple flask app to app.py<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>from flask import Flask\nfrom flask import jsonify\n\napp = Flask(__name__)\n\n@app.route('\/')\ndef hello():\n    \"\"\"Return a friendly HTTP greeting.\"\"\"\n    print(\"I am inside hello world\")\n    return 'Hello World! CD'\n\n@app.route('\/echo\/&lt;name>')\ndef echo(name):\n    print(f\"This was placed in the url: new-{name}\")\n    val = {\"new-name\": name}\n    return jsonify(val)\n\n\nif __name__ == '__main__':\n    app.debug = True\n    app.run()<\/code><\/pre>\n\n\n\n<p>Then just run the app with <\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>python app.py<\/code><\/pre>\n\n\n\n<p>Then we can just test the app using curl in a new terminal, like this:<\/p>\n\n\n\n<figure class=\"wp-block-image size-full\"><img loading=\"lazy\" decoding=\"async\" width=\"643\" height=\"219\" src=\"https:\/\/www.mutareb.com\/wp-content\/uploads\/2023\/04\/grafik-5.png\" alt=\"\" class=\"wp-image-155\" srcset=\"https:\/\/www.mutareb.com\/wp-content\/uploads\/2023\/04\/grafik-5.png 643w, https:\/\/www.mutareb.com\/wp-content\/uploads\/2023\/04\/grafik-5-300x102.png 300w\" sizes=\"auto, (max-width: 643px) 100vw, 643px\" \/><\/figure>\n\n\n\n<p>Now we can deploy the app, we just need to make sure AWS EB ignores the virtual environment we created earlier:<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>touch .ebignore\necho \"virt\" > .ebignore<\/code><\/pre>\n\n\n\n<p>Now we can initiate the deployment:<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>eb init -p python-3.7 flask-tutorial\neb create flask-tutorial<\/code><\/pre>\n\n\n\n<p>AWS EB will now create all needed components we would otherwise needed to create manually:<\/p>\n\n\n\n<ul class=\"wp-block-list\">\n<li>EC2 instances (VPS)<\/li>\n\n\n\n<li>Security group (firewall rules to the VPS)<\/li>\n\n\n\n<li>S3 bucket (storage)<\/li>\n\n\n\n<li>CloudWatch alarms (performance monitoring for up or down scaling)<\/li>\n\n\n\n<li>CloudFormation stack (all the resources required to run a web application, such as a web server, a database, and networking rules)<\/li>\n\n\n\n<li>Domain name<\/li>\n<\/ul>\n\n\n\n<p><\/p>\n","protected":false},"excerpt":{"rendered":"<p>Elastic Beanstalk is the PaaS component of AWS, it will automatically handle the details of capacity provisioning, load balancing, scaling, and application health monitoring. We will go to AWS Elastic Beanstalk Documentation, look for &#8220;Install the EB CLI&#8221; to install the eb cli on the cloud9 environment. At the time of writing it was just&hellip; <a class=\"more-link\" href=\"https:\/\/www.mutareb.com\/index.php\/2023\/04\/02\/testing-out-aws-elastic-beanstalk\/\">Continue reading <span class=\"screen-reader-text\">Testing out AWS Elastic Beanstalk<\/span><\/a><\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"open","ping_status":"closed","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[31],"tags":[32,33],"series":[35],"class_list":["post-154","post","type-post","status-publish","format-standard","hentry","category-cloud-computing","tag-aws","tag-elastic-beanstalk","series-cloud-computing","entry"],"_links":{"self":[{"href":"https:\/\/www.mutareb.com\/index.php\/wp-json\/wp\/v2\/posts\/154","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/www.mutareb.com\/index.php\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/www.mutareb.com\/index.php\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/www.mutareb.com\/index.php\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/www.mutareb.com\/index.php\/wp-json\/wp\/v2\/comments?post=154"}],"version-history":[{"count":1,"href":"https:\/\/www.mutareb.com\/index.php\/wp-json\/wp\/v2\/posts\/154\/revisions"}],"predecessor-version":[{"id":156,"href":"https:\/\/www.mutareb.com\/index.php\/wp-json\/wp\/v2\/posts\/154\/revisions\/156"}],"wp:attachment":[{"href":"https:\/\/www.mutareb.com\/index.php\/wp-json\/wp\/v2\/media?parent=154"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/www.mutareb.com\/index.php\/wp-json\/wp\/v2\/categories?post=154"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/www.mutareb.com\/index.php\/wp-json\/wp\/v2\/tags?post=154"},{"taxonomy":"series","embeddable":true,"href":"https:\/\/www.mutareb.com\/index.php\/wp-json\/wp\/v2\/series?post=154"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}