<?xml version="1.0" encoding="utf-8"?><feed xmlns="http://www.w3.org/2005/Atom" ><generator uri="https://jekyllrb.com/" version="3.9.1">Jekyll</generator><link href="https://www.nageshdn.com/feed.xml" rel="self" type="application/atom+xml" /><link href="https://www.nageshdn.com/" rel="alternate" type="text/html" /><updated>2021-05-07T19:21:00+05:30</updated><id>https://www.nageshdn.com/feed.xml</id><title type="html">NAGESH D N</title><subtitle>Professional  in Datacenter/Cloud Technologies,AWS Solution Architecture</subtitle><author><name>Nagesh</name></author><entry><title type="html">Python Vaccine API Implementation</title><link href="https://www.nageshdn.com/2021/05/07/Vaccine-API-Bot.html" rel="alternate" type="text/html" title="Python Vaccine API Implementation" /><published>2021-05-07T00:00:00+05:30</published><updated>2021-05-07T00:00:00+05:30</updated><id>https://www.nageshdn.com/2021/05/07/Vaccine%20API%20Bot</id><content type="html" xml:base="https://www.nageshdn.com/2021/05/07/Vaccine-API-Bot.html">&lt;p&gt;Currently Govt has open sourced covid vaccine availability API’s in India as given &lt;a href=&quot;https://apisetu.gov.in/public/marketplace/api/cowin&quot;&gt;here&lt;/a&gt;, Vaccine slots are limited and  difficult to know when those slots gets opened.
Here is simple bot created to monitor the vaccine slots and notify interested users when those slots are available.&lt;/p&gt;

&lt;div class=&quot;language-plaintext highlighter-rouge&quot;&gt;&lt;div class=&quot;highlight&quot;&gt;&lt;pre class=&quot;highlight&quot;&gt;&lt;code&gt;#!/usr/bin/env python3
import json,urllib3,datetime,time,logging,telegram,configparser

config = configparser.ConfigParser()
config.read_file(open('api.conf'))
weburl = config.get('cowin', 'url')
TOKEN = config.get('telegram', 'token')
CHAT_ID = config.get('telegram', 'chat_id')
x=datetime.datetime.now()

day=x.strftime(&quot;%d-%m-%Y&quot;)
weburl+=day
http = urllib3.PoolManager()
logging.basicConfig(filename='./vaccine.log',level=logging.INFO,format='%(asctime)s %(message)s')
bot = telegram.Bot(token=TOKEN)

while True:
    found=0
    try:
        response = http.request('GET', weburl)
        json_data = json.loads(response.data)
    except Exception as ex:
        logging.info(&quot;API is not responding!&quot;)
        time.sleep(10)
        continue

    for x in json_data['centers']:
        for y in x['sessions']:
            if y['min_age_limit'] == 18 and y['available_capacity'] &amp;gt; 0:
                #print(y)
                message = '18+ vaccine available in #BBMP: '+ str(x['pincode']) +' '+ str(y['date'])+ ' ' + x['name'] +' Avail slots: '+ str(y['available_capacity'])
                logging.info(message)
                bot.sendMessage(chat_id = CHAT_ID, text =message)
                found=1
                break
            else:
                continue
            break
    if (found == 0):
        time.sleep(4)
    else:
        continue
&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;&lt;/div&gt;

&lt;p&gt;API is  enforcing 100 calls/5 mins rate limit per IP, which translates to 1 call/3 seconds,hence after every iteration, the bot sleeps for 4 seconds
 Incase slots are open ( found=1), need to validate and alert without this 4 seconds delay, hence utilizes double break points and skips the 4 seconds delay with found=1 flag&lt;/p&gt;

&lt;p&gt;Example snapshot of the telegram alerts is as follows:
 &lt;img src=&quot;/assets/screenshots/telegram-vaccine-slot.jpg&quot; alt=&quot;Telegram Notification Snapshot&quot; /&gt;&lt;/p&gt;</content><author><name>Nagesh</name></author><category term="python3" /><category term="linux" /><category term="API" /><summary type="html">Currently Govt has open sourced covid vaccine availability API’s in India as given here, Vaccine slots are limited and difficult to know when those slots gets opened. Here is simple bot created to monitor the vaccine slots and notify interested users when those slots are available. #!/usr/bin/env python3 import json,urllib3,datetime,time,logging,telegram,configparser</summary></entry><entry><title type="html">Systemd timers for cron activities</title><link href="https://www.nageshdn.com/2020/12/21/Systemd-timers-for-cron-activities.html" rel="alternate" type="text/html" title="Systemd timers for cron activities" /><published>2020-12-21T00:00:00+05:30</published><updated>2020-12-21T00:00:00+05:30</updated><id>https://www.nageshdn.com/2020/12/21/%20%20Systemd%20timers%20for%20cron%20activities</id><content type="html" xml:base="https://www.nageshdn.com/2020/12/21/Systemd-timers-for-cron-activities.html">&lt;p&gt;Cron utility in Linux has been helpful to schedule tasks to run at a scheduled time.  A few of the disadvantages of cron are&lt;/p&gt;
&lt;ol&gt;
  &lt;li&gt;If Instance/server is not available/down at the cron schedule, cron doesn’t run those tasks until the next event is triggered&lt;/li&gt;
  &lt;li&gt;If the cron task need to run other tasks after running the main task at the scheduled time, there are only hacks to create this dependency&lt;/li&gt;
  &lt;li&gt;If the cron task needs to run within a given time interval to avoid running at the same time&lt;/li&gt;
  &lt;li&gt;If a cron task needs to run after an event, such as 3 minutes after the system restarted. Cron doesn’t support this functionality&lt;/li&gt;
  &lt;li&gt;To check the status of the last cron task to see if it ran/failed with logs&lt;/li&gt;
&lt;/ol&gt;

&lt;p&gt;Most of the above issues require an alternative to cron. the above issues are fixed using system timer in Linux  as follows:&lt;/p&gt;

&lt;p&gt;Example Systemd Timer unit file&lt;/p&gt;

&lt;div class=&quot;language-plaintext highlighter-rouge&quot;&gt;&lt;div class=&quot;highlight&quot;&gt;&lt;pre class=&quot;highlight&quot;&gt;&lt;code&gt;# test.timer
[Unit] 
Description=Runs the test.service 5 minutes after boot-up &amp;amp; at/around 6 PM every weekday.
[Timer] 
OnCalendar=Mon..Fri 18:00
## supports multiple time formats
Persistent=True
##If the machine is powered down and missed Oncalendar event, Persistent=true triggers if time has elapsed.
OnBootSec=5 m 
## Event-Based, triggers the event 5 minutes after the machine is rebooted
RandomizedDelaySec=1800
## Randomly add up to 30 mins to the schedule. This is to ensure the task runs between 6 PM to 6.30 PM.

Unit=test.service 
## service/task which needs to be run when the event/time occurs
[Install] 
WantedBy=basic.target
&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;&lt;/div&gt;

&lt;p&gt;Example Systemd service unit file
    # test.service
    [Unit] 
    Description= test.service that needs to be run&lt;/p&gt;

&lt;div class=&quot;language-plaintext highlighter-rouge&quot;&gt;&lt;div class=&quot;highlight&quot;&gt;&lt;pre class=&quot;highlight&quot;&gt;&lt;code&gt;[Service]
ExecStartPre=&amp;lt;some executable&amp;gt;
ExecStart=&amp;lt;some executable&amp;gt;
ExecStartPost=&amp;lt;some executable&amp;gt;
## ExectStart runs only if ExecStartPre is successful and ExecStartPost runs only if ExecStart is successful
[Install] 
WantedBy=basic.target
&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;&lt;/div&gt;

&lt;p&gt;To list all the system timers,last/next schedule&lt;/p&gt;

&lt;div class=&quot;language-plaintext highlighter-rouge&quot;&gt;&lt;div class=&quot;highlight&quot;&gt;&lt;pre class=&quot;highlight&quot;&gt;&lt;code&gt;ubuntu@ip-11-223-3-40:/tmp$ systemctl list-timers --all
NEXT                        LEFT          LAST                        PASSED       UNIT                         ACTIVATES                     
Tue 2020-12-22 00:00:00 IST 1h 19min left Mon 2020-12-21 16:06:50 IST 6h ago       logrotate.timer              logrotate.service             
Tue 2020-12-22 00:00:00 IST 1h 19min left Mon 2020-12-21 16:09:06 IST 6h ago       man-db.timer                 man-db.service                
Tue 2020-12-22 01:02:49 IST 2h 22min left Mon 2020-12-21 15:04:47 IST 7h ago       motd-news.timer              motd-news.service             
Tue 2020-12-22 03:01:02 IST 4h 20min left Mon 2020-12-21 15:05:43 IST 7h ago       certbot.timer                certbot.service               
Tue 2020-12-22 04:58:50 IST 6h left       Mon 2020-12-21 14:54:08 IST 7h ago       apt-daily.timer              apt-daily.service             
&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;&lt;/div&gt;

&lt;p&gt;To Check the syntax of calendar event&lt;/p&gt;

&lt;div class=&quot;language-plaintext highlighter-rouge&quot;&gt;&lt;div class=&quot;highlight&quot;&gt;&lt;pre class=&quot;highlight&quot;&gt;&lt;code&gt;ubuntu@ip-11-223-3-40:~/tmp$ systemd-analyze calendar &quot;Mon..Fri 06:01&quot;
  Original form: Mon..Fri 06:01             
Normalized form: Mon..Fri *-*-* 06:01:00    
    Next elapse: Tue 2020-12-22 06:01:00 IST
       (in UTC): Tue 2020-12-22 00:31:00 UTC
       From now: 7h left    
&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;&lt;/div&gt;</content><author><name>Nagesh</name></author><category term="systemd" /><category term="linux" /><category term="cron" /><summary type="html">Cron utility in Linux has been helpful to schedule tasks to run at a scheduled time. A few of the disadvantages of cron are If Instance/server is not available/down at the cron schedule, cron doesn’t run those tasks until the next event is triggered If the cron task need to run other tasks after running the main task at the scheduled time, there are only hacks to create this dependency If the cron task needs to run within a given time interval to avoid running at the same time If a cron task needs to run after an event, such as 3 minutes after the system restarted. Cron doesn’t support this functionality To check the status of the last cron task to see if it ran/failed with logs</summary></entry><entry><title type="html">Performance Optimization of http endpoints</title><link href="https://www.nageshdn.com/2020/04/01/Performance-Optimization-of-http-endpoints.html" rel="alternate" type="text/html" title="Performance Optimization of http endpoints" /><published>2020-04-01T00:00:00+05:30</published><updated>2020-04-01T00:00:00+05:30</updated><id>https://www.nageshdn.com/2020/04/01/Performance%20Optimization%20of%20http%20endpoints</id><content type="html" xml:base="https://www.nageshdn.com/2020/04/01/Performance-Optimization-of-http-endpoints.html">&lt;p&gt;http endpoints running on a small instances which needs to be optimized for peformance. can be done using 2 ways&lt;/p&gt;

&lt;ol&gt;
  &lt;li&gt;&lt;strong&gt;“Throwing resource to the problem”&lt;/strong&gt; - easier approach,increase size of the backend instance, this increases cost.&lt;/li&gt;
  &lt;li&gt;&lt;strong&gt;“Optimize Protocols”&lt;/strong&gt; - to improve/reduce the traffic reaching small instance, similar or marginal cost increase.&lt;/li&gt;
&lt;/ol&gt;

&lt;p&gt;Some opportunities to optimize protocols in nginx:&lt;/p&gt;

&lt;ul&gt;
  &lt;li&gt;
    &lt;h4 id=&quot;http2-instead-of-http11&quot;&gt;http/2 instead of http/1.1&lt;/h4&gt;
    &lt;p&gt;http/2 provides header compression,multiplexing and server push features, since http request is foundational, any small improvement
  will have huge impact on performance and costs.&lt;/p&gt;

    &lt;p&gt;enabling http/2 protocol in nginx can be done as&lt;/p&gt;

    &lt;div class=&quot;language-plaintext highlighter-rouge&quot;&gt;&lt;div class=&quot;highlight&quot;&gt;&lt;pre class=&quot;highlight&quot;&gt;&lt;code&gt; listen 443 ssl http2;
&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;    &lt;/div&gt;
  &lt;/li&gt;
  &lt;li&gt;
    &lt;h4 id=&quot;tls13-and--tls12&quot;&gt;TLS1.3 and  TLS1.2&lt;/h4&gt;
    &lt;p&gt;Transport Layer Security(TLS) is successor of Secure Sockets Layer(SSL), TLS 1.2 requires 2 round trips for handshake, TLS 1.3
  completes handshake with 1 round trip, this reduces encryption latency by 50% and thus improves performance. &lt;br /&gt;
  TLS 1.3 also offers 0-RTT (zero Round trip time) Resumption, which helps clients which are previously connected to server with
  zero-handshake and thus improves performance, this feature is vulnerable to  Replay attacks. Not all clients supports TLS1.3, hence
  better to enable both TLS 1.3 and TLS 1.2&lt;/p&gt;

    &lt;p&gt;enabling TLS V1.3 and 0-RTT in nginx can be done as&lt;/p&gt;

    &lt;div class=&quot;language-plaintext highlighter-rouge&quot;&gt;&lt;div class=&quot;highlight&quot;&gt;&lt;pre class=&quot;highlight&quot;&gt;&lt;code&gt; ssl_protocols TLSv1.3 TLSv1.2;
 ssl_early_data on;
&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;    &lt;/div&gt;
  &lt;/li&gt;
  &lt;li&gt;
    &lt;h4 id=&quot;http3--and-http2&quot;&gt;http/3  and http/2&lt;/h4&gt;
    &lt;p&gt;http/3 is evovled version of http/2 and upcoming standard for http, http/3 is based on QUIC (Quick UDP Internet Connections) which offers much improved handshake 
  than TCP+TLS 1.3 combined and other performance improvements.&lt;/p&gt;

    &lt;p&gt;support to enable this protocol in nginx is limited , and expected  to be added soon&lt;/p&gt;
  &lt;/li&gt;
&lt;/ul&gt;</content><author><name>Nagesh</name></author><category term="Peformance" /><category term="nginx" /><category term="http" /><summary type="html">http endpoints running on a small instances which needs to be optimized for peformance. can be done using 2 ways</summary></entry><entry><title type="html">S3 website public access prevention</title><link href="https://www.nageshdn.com/2020/02/20/S3-website-public-access-prevention.html" rel="alternate" type="text/html" title="S3 website public access prevention" /><published>2020-02-20T00:00:00+05:30</published><updated>2020-02-20T00:00:00+05:30</updated><id>https://www.nageshdn.com/2020/02/20/S3%20website%20public%20access%20prevention</id><content type="html" xml:base="https://www.nageshdn.com/2020/02/20/S3-website-public-access-prevention.html">&lt;p&gt;S3 public websites have limitation to access only using http and not https, this can be addressed using cloudfront(http/https) as 
frontend of website and S3 public website as backend(http). However both frontend and backend can be accessed separately and can be considered
as duplicates.&lt;/p&gt;

&lt;p&gt;To ensure access to S3 public website only from cloudfront, cloudfront can pass  origin header as Referer which S3 would whitelist using bucket policy 
as given below&lt;/p&gt;

&lt;div class=&quot;language-plaintext highlighter-rouge&quot;&gt;&lt;div class=&quot;highlight&quot;&gt;&lt;pre class=&quot;highlight&quot;&gt;&lt;code&gt;{
    &quot;Version&quot;: &quot;2012-10-17&quot;,
    &quot;Statement&quot;: [
        {
            &quot;Sid&quot;: &quot;PublicReadForGetBucketObjects&quot;,
            &quot;Effect&quot;: &quot;Allow&quot;,
            &quot;Principal&quot;: &quot;*&quot;,
            &quot;Action&quot;: &quot;s3:GetObject&quot;,
            &quot;Resource&quot;: &quot;arn:aws:s3:::swbucketname/*&quot;,
            &quot;Condition&quot;: {
                &quot;StringLike&quot;: {
                    &quot;aws:Referer&quot;: &quot;secretfors3&quot;
                }
            }
        }
    ]
}
&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;&lt;/div&gt;
&lt;p&gt;this effectively restricts all public access  limited to cloudfront,which caches frequent data and improves speed.&lt;/p&gt;</content><author><name>Nagesh</name></author><category term="S3" /><category term="Cloudfront" /><category term="AWS" /><summary type="html">S3 public websites have limitation to access only using http and not https, this can be addressed using cloudfront(http/https) as frontend of website and S3 public website as backend(http). However both frontend and backend can be accessed separately and can be considered as duplicates.</summary></entry><entry><title type="html">Serverless Enterprise Logging issues</title><link href="https://www.nageshdn.com/2020/02/15/Serverless-Enterprise-Logging-issues.html" rel="alternate" type="text/html" title="Serverless Enterprise Logging issues" /><published>2020-02-15T00:00:00+05:30</published><updated>2020-02-15T00:00:00+05:30</updated><id>https://www.nageshdn.com/2020/02/15/Serverless%20Enterprise%20Logging%20issues</id><content type="html" xml:base="https://www.nageshdn.com/2020/02/15/Serverless-Enterprise-Logging-issues.html">&lt;p&gt;While developing and deploying Function as a service(Faas) applications leveraging AWS Lambda ,API Gateways etc. &lt;a href=&quot;https://serverless.com/&quot;&gt;Serverless&lt;/a&gt; frameworks
promised to keep development and deployments simple and enabling public cloud of choice.&lt;/p&gt;

&lt;p&gt;Serverless Enterprise/Pro Edition which offers monitoring,alerts etc to serverless applications resulted in huge logging for each
function invocations e.g.&lt;/p&gt;
&lt;div class=&quot;language-plaintext highlighter-rouge&quot;&gt;&lt;div class=&quot;highlight&quot;&gt;&lt;pre class=&quot;highlight&quot;&gt;&lt;code&gt;SERVERLESS_ENTERPRISE 
{
    &quot;type&quot;: &quot;transaction&quot;,
    &quot;origin&quot;: &quot;sls-agent&quot;,
    &quot;payload&quot;: {
        &quot;duration&quot;: 576.2143135070801,
        &quot;endTime&quot;: &quot;2020-02-15T05:18:46.646536Z&quot;,
        &quot;logs&quot;: {},
        &quot;operationName&quot;: &quot;s-transaction-function&quot;,
        &quot;schemaType&quot;: &quot;s-span&quot;,
        &quot;schemaVersion&quot;: &quot;0.0&quot;,
        &quot;spanContext&quot;: {
            &quot;spanId&quot;: &quot;1c28085b-efd5-4591-865a-e38ef0bda0e7&quot;,
            &quot;traceId&quot;: &quot;0874e9f5-ed95-4e3c-aa37-d16a54f3602c&quot;,
            &quot;xTraceId&quot;: &quot;Root=1-5e477f35-53f776209c7518c6e40ea991;Parent=5412c6a632e94e9d;Sampled=0&quot;
        },
        .... tens of such lines for each function invocation

&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;&lt;/div&gt;
&lt;p&gt;There are no documented ways to disable  serverless enterprise logging and reporting,
A simple Programming mistake which triggered hundreds of function calls to Lambda  resulted in &amp;gt;80 GB Cloud watch logs, and more than 
2GB data transfer out to serverless.com, which exceeded AWS budgets by many folds.&lt;/p&gt;

&lt;p&gt;Steps to Control  serverless logging and bill shocks in AWS :&lt;/p&gt;

&lt;ol&gt;
  &lt;li&gt;Simple step to disable serverless enterprise logging is - logout from serverless using cli &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;sls logout&lt;/code&gt; and comment  &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;app&lt;/code&gt; and &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;org&lt;/code&gt;
labels in &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;servererless.yml&lt;/code&gt;&lt;/li&gt;
  &lt;li&gt;Disable unwanted logging/warnings generated by functions, Serverless Enterprise framework with Python3.8 caused multiple warnings, migrating it back
to python3.6 resolved it and saved logging.&lt;/li&gt;
  &lt;li&gt;Implement Guard Rails for number of  AWS lambda invocations using ReservedConcurrency to reasonable limits (default account 
concurrency limit which allows upto 1000 lamnba functions to run in parallel)&lt;/li&gt;
  &lt;li&gt;Implement Rate limiter for AWS API gateway end points to be within reasonable/expected limits.&lt;/li&gt;
&lt;/ol&gt;</content><author><name>Nagesh</name></author><category term="Serverless" /><category term="cloudwatch" /><category term="AWS" /><summary type="html">While developing and deploying Function as a service(Faas) applications leveraging AWS Lambda ,API Gateways etc. Serverless frameworks promised to keep development and deployments simple and enabling public cloud of choice.</summary></entry><entry><title type="html">Stop Cloud9 IDE immediately to save costs</title><link href="https://www.nageshdn.com/2020/02/07/Stop-Cloud9-IDE-immediately.html" rel="alternate" type="text/html" title="Stop Cloud9 IDE immediately to save costs" /><published>2020-02-07T00:00:00+05:30</published><updated>2020-02-07T00:00:00+05:30</updated><id>https://www.nageshdn.com/2020/02/07/Stop%20Cloud9%20IDE%20immediately</id><content type="html" xml:base="https://www.nageshdn.com/2020/02/07/Stop-Cloud9-IDE-immediately.html">&lt;p&gt;AWS cloud9 IDE simplifed access and development in Cloud by using cloud native IDE and associated terminal for CLI access.
To reduce wastage of unused EC2 instances which are the backend of Cloud9, Cloud9 IDE detects presence of user based on activity 
and shutdowns EC2 instances using predetermined interval.&lt;/p&gt;

&lt;p&gt;The minimum time to configure inactivity is 30 minutes, which means when user is not using cloud9  upto 30 mins, Cloud9 shutsdown
EC2 instance.&lt;/p&gt;

&lt;p&gt;To enable immediate shutdown of cloud9 environment on determinstic use cases, user can accomplish this by following process.&lt;/p&gt;

&lt;p&gt;1.write lambda function which stops the requested EC2 instance ID. simple code for this is..&lt;/p&gt;

&lt;div class=&quot;language-python highlighter-rouge&quot;&gt;&lt;div class=&quot;highlight&quot;&gt;&lt;pre class=&quot;highlight&quot;&gt;&lt;code&gt;&lt;span class=&quot;kn&quot;&gt;import&lt;/span&gt; &lt;span class=&quot;nn&quot;&gt;boto3&lt;/span&gt;
&lt;span class=&quot;n&quot;&gt;region&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;=&lt;/span&gt; &lt;span class=&quot;s&quot;&gt;'us-east-1'&lt;/span&gt;
&lt;span class=&quot;n&quot;&gt;ec2&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;=&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;boto3&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;client&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;s&quot;&gt;'ec2'&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;,&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;region_name&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;=&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;region&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;)&lt;/span&gt;
&lt;span class=&quot;k&quot;&gt;def&lt;/span&gt; &lt;span class=&quot;nf&quot;&gt;stopEC2&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;event&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;,&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;context&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;):&lt;/span&gt;
    &lt;span class=&quot;k&quot;&gt;print&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;s&quot;&gt;&quot;Received Instance ID:&quot;&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;+&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;event&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;[&lt;/span&gt;&lt;span class=&quot;s&quot;&gt;'queryStringParameters'&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;][&lt;/span&gt;&lt;span class=&quot;s&quot;&gt;'instance_id'&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;])&lt;/span&gt;
    &lt;span class=&quot;k&quot;&gt;if&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;(&lt;/span&gt;
            &lt;span class=&quot;n&quot;&gt;event&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;[&lt;/span&gt;&lt;span class=&quot;s&quot;&gt;'httpMethod'&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;]&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;==&lt;/span&gt; &lt;span class=&quot;s&quot;&gt;'GET'&lt;/span&gt; &lt;span class=&quot;ow&quot;&gt;and&lt;/span&gt;
            &lt;span class=&quot;n&quot;&gt;event&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;[&lt;/span&gt;&lt;span class=&quot;s&quot;&gt;'path'&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;]&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;==&lt;/span&gt; &lt;span class=&quot;s&quot;&gt;&quot;/someconfidentialpath/ec2stop&quot;&lt;/span&gt; &lt;span class=&quot;ow&quot;&gt;and&lt;/span&gt;
            &lt;span class=&quot;n&quot;&gt;event&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;[&lt;/span&gt;&lt;span class=&quot;s&quot;&gt;'queryStringParameters'&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;][&lt;/span&gt;&lt;span class=&quot;s&quot;&gt;'instance_id'&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;]&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;!=&lt;/span&gt; &lt;span class=&quot;s&quot;&gt;''&lt;/span&gt;
            &lt;span class=&quot;p&quot;&gt;):&lt;/span&gt;
        &lt;span class=&quot;n&quot;&gt;instance_id&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;=&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;event&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;[&lt;/span&gt;&lt;span class=&quot;s&quot;&gt;'queryStringParameters'&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;][&lt;/span&gt;&lt;span class=&quot;s&quot;&gt;'instance_id'&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;]&lt;/span&gt;
        &lt;span class=&quot;n&quot;&gt;ec2&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;stop_instances&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;InstanceIds&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;=&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;[&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;instance_id&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;])&lt;/span&gt;
        &lt;span class=&quot;k&quot;&gt;print&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;s&quot;&gt;'stopped your instances: '&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;+&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;instance_id&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;)&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;&lt;/div&gt;

&lt;ol&gt;
  &lt;li&gt;
    &lt;p&gt;Deploy the above lambda function with IAM role which has permission to Stop EC2 instances.&lt;/p&gt;
  &lt;/li&gt;
  &lt;li&gt;
    &lt;p&gt;Configure AWS API Gateway which proxies the request to above given lambda function.&lt;/p&gt;
  &lt;/li&gt;
  &lt;li&gt;
    &lt;p&gt;Configure a http bookmark for API Gateway with querystring parameters as instance ID.
 e.g: https://api.nageshdn.com/someconfidentialpath/ec2stop?instance_id=i-012345678923&lt;/p&gt;
  &lt;/li&gt;
&lt;/ol&gt;

&lt;p&gt;Whenever user is leaving the desk, user just need to click the above http bookmark, which will trigger lambda function to shutdown
EC2 instances and saves costs upto 30 mins every time.&lt;/p&gt;</content><author><name>Nagesh</name></author><category term="Cloud9" /><category term="EC2" /><category term="AWS" /><summary type="html">AWS cloud9 IDE simplifed access and development in Cloud by using cloud native IDE and associated terminal for CLI access. To reduce wastage of unused EC2 instances which are the backend of Cloud9, Cloud9 IDE detects presence of user based on activity and shutdowns EC2 instances using predetermined interval.</summary></entry><entry><title type="html">Rolling back github private repo</title><link href="https://www.nageshdn.com/2019/04/29/Rolling-back-github-private-repo.html" rel="alternate" type="text/html" title="Rolling back github private repo" /><published>2019-04-29T00:00:00+05:30</published><updated>2019-04-29T00:00:00+05:30</updated><id>https://www.nageshdn.com/2019/04/29/Rolling%20back%20github%20private%20repo</id><content type="html" xml:base="https://www.nageshdn.com/2019/04/29/Rolling-back-github-private-repo.html">&lt;p&gt;As detailed in the earlier post,hosted this website in github private repo with github pages until today.&lt;/p&gt;

&lt;p&gt;Last week,Received following notification about github pages not supported in private-free accounts&lt;/p&gt;

&lt;p&gt;&lt;img src=&quot;/assets/screenshots/github_notify.png&quot; alt=&quot;email &quot; /&gt;&lt;/p&gt;

&lt;p&gt;Hence rolling back github private repo with github pages to public repo to continue to host this blog.&lt;/p&gt;</content><author><name>Nagesh</name></author><category term="Github" /><category term="Private" /><category term="Hosting" /><summary type="html">As detailed in the earlier post,hosted this website in github private repo with github pages until today.</summary></entry><entry><title type="html">Github Private repo for pages</title><link href="https://www.nageshdn.com/2019/01/13/Github-Private-repo-for-hosting-pages.html" rel="alternate" type="text/html" title="Github Private repo for pages" /><published>2019-01-13T00:00:00+05:30</published><updated>2019-01-13T00:00:00+05:30</updated><id>https://www.nageshdn.com/2019/01/13/Github%20Private%20repo%20for%20hosting%20pages</id><content type="html" xml:base="https://www.nageshdn.com/2019/01/13/Github-Private-repo-for-hosting-pages.html">&lt;p&gt;This website  uses github as repository/editor for markdown and uses AWS for distribution using S3/Cloudfront. Github repo has to be public/open if it is not subscribed to paid plans. The other alternative to have private repo is bitbucket or AWS codecommit, which are free, but not as easy/popular compared to  github.&lt;/p&gt;

&lt;p&gt;Earlier this month github announced  unlimited free private repository with collobarators limited upto 3. Hence moved this repository to private, However this breaks github pages features, which works only if it is public or pro account. Since this site is using github pages only as failover (when AWS S3 is down).&lt;/p&gt;</content><author><name>Nagesh</name></author><category term="Github" /><category term="hosting" /><category term="AWS" /><summary type="html">This website uses github as repository/editor for markdown and uses AWS for distribution using S3/Cloudfront. Github repo has to be public/open if it is not subscribed to paid plans. The other alternative to have private repo is bitbucket or AWS codecommit, which are free, but not as easy/popular compared to github.</summary></entry><entry><title type="html">Github Private repo for hosting pages</title><link href="https://www.nageshdn.com/2019/01/13/Github-Private-repo-pages.html" rel="alternate" type="text/html" title="Github Private repo for hosting pages" /><published>2019-01-13T00:00:00+05:30</published><updated>2019-01-13T00:00:00+05:30</updated><id>https://www.nageshdn.com/2019/01/13/Github%20Private%20repo%20pages</id><content type="html" xml:base="https://www.nageshdn.com/2019/01/13/Github-Private-repo-pages.html">&lt;p&gt;This website uses github as repository/editor for markdown and  AWS for distribution using S3/Cloudfront. Github repo has to be public/open if it is not subscribed to paid plans. The other alternative to have private repo is bitbucket or AWS codecommit.&lt;/p&gt;

&lt;p&gt;Earlier this month github announced  unlimited free private repository with collobarators limited upto 3 users. Hence moved this repository to private, However this breaks github pages features, which works only if it is public or pro account. Since this site is using github pages only as failover (when AWS S3 is down).&lt;/p&gt;

&lt;p&gt;&lt;img src=&quot;/assets/screenshots/github_private_pages.png&quot; alt=&quot;Disabled Pages for private repo &quot; /&gt;&lt;/p&gt;

&lt;p&gt;Need to explore alternatives for backup/github pages for private repo.&lt;/p&gt;</content><author><name>Nagesh</name></author><category term="Github" /><category term="Private" /><category term="Hosting" /><summary type="html">This website uses github as repository/editor for markdown and AWS for distribution using S3/Cloudfront. Github repo has to be public/open if it is not subscribed to paid plans. The other alternative to have private repo is bitbucket or AWS codecommit.</summary></entry><entry><title type="html">S3 Failover to Github</title><link href="https://www.nageshdn.com/2018/12/20/S3-Failover-to-Github.html" rel="alternate" type="text/html" title="S3 Failover to Github" /><published>2018-12-20T00:00:00+05:30</published><updated>2018-12-20T00:00:00+05:30</updated><id>https://www.nageshdn.com/2018/12/20/S3%20Failover%20to%20Github</id><content type="html" xml:base="https://www.nageshdn.com/2018/12/20/S3-Failover-to-Github.html">&lt;p&gt;AWS S3 storage and S3 websites are highest available services in terms of uptime, as they are backed by AWS SLA of 99.99% availability in a given year. AWS &lt;a href=&quot;https://status.aws.amazon.com/&quot;&gt;health status&lt;/a&gt; also leverages S3, however there are chances still S3 can go down, here is &lt;a href=&quot;https://www.theregister.co.uk/2017/03/01/aws_s3_outage/&quot;&gt;report&lt;/a&gt;, where AWS S3 was down for few hours and AWS also had no access to  update the health status.&lt;/p&gt;

&lt;p&gt;With this context, is there a way to automatically failover when highly reliably AWS S3 fails and still run your services?
since this site relies on github as a repo/editor, few months ago, github also started to support https on &lt;a href=&quot;https://blog.github.com/2018-05-01-github-pages-custom-domains-https/&quot;&gt;custom domain names&lt;/a&gt; , Hence github pages is right alternative for AWS S3 for static sites. So the change required is to add github pages as failover whenever underlying S3  fails or configuration/deployment failure to S3.&lt;/p&gt;

&lt;p&gt;github pages are automatically available at username.github.io , need to update the Route 53 DNS record from existing simple/Alias record to Failover(Primary)/CNAME. github does not supports cname at apex domain(example.com), Hence need to resolve this using Alias record which redirects example.com to www.example.com ( setting redirect at S3 bucket).&lt;/p&gt;

&lt;p&gt;Route 53 health check is configured to check the status of website using index.html page over port 80 at S3 public endpoint,this would be free of charge as it is using AWS endpoint, default health check would check every 30 seconds from more than 10 s3 regions, this healthchecks would generate around 1,000,000 get request against the S3 bucket, made changes to reduce this to minimum required 3 regions to reduce this flooding of the requests.&lt;/p&gt;

&lt;p&gt;Created second record as Failover(Secondary)/CNAME record with target as username.github.io without any healthcheck,to simulate the failover,changed S3 index.html object to be unavailable, here is how DNS health check finds it and DNS failover works when this occurs.&lt;/p&gt;

&lt;ul&gt;
  &lt;li&gt;
    &lt;p&gt;DNS healthcheck Notification over email
&lt;img src=&quot;/assets/screenshots/20181220-dnshealthcheck.png&quot; alt=&quot;DNS healthcheck Notification&quot; /&gt;&lt;/p&gt;
  &lt;/li&gt;
  &lt;li&gt;
    &lt;p&gt;DNS response on failure (points to username.github.io)
&lt;img src=&quot;/assets/screenshots/20181220-dnsresponse.png&quot; alt=&quot;DNS response on failure&quot; /&gt;&lt;/p&gt;
  &lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;On failover to secondary(github pages), website worked with fully functionalty including support for https for both apex and subdomain as required. Main advantage with this change is  automatic standby/failover and cost optimizations if the primary website using AWS becomes costly to manage (CDN/S3 charges), can easily make Secondary as Primary by just modifying an object in S3/Route 53.&lt;/p&gt;</content><author><name>Nagesh</name></author><category term="S3" /><category term="Route53" /><category term="Github" /><category term="Optimization" /><summary type="html">AWS S3 storage and S3 websites are highest available services in terms of uptime, as they are backed by AWS SLA of 99.99% availability in a given year. AWS health status also leverages S3, however there are chances still S3 can go down, here is report, where AWS S3 was down for few hours and AWS also had no access to update the health status.</summary></entry></feed>