<?xml version="1.0" encoding="UTF-8"?><rss xmlns:dc="http://purl.org/dc/elements/1.1/" xmlns:content="http://purl.org/rss/1.0/modules/content/" xmlns:atom="http://www.w3.org/2005/Atom" version="2.0" xmlns:cc="http://cyber.law.harvard.edu/rss/creativeCommonsRssModule.html">
    <channel>
        <title><![CDATA[Stories by liang boyuan on Medium]]></title>
        <description><![CDATA[Stories by liang boyuan on Medium]]></description>
        <link>https://medium.com/@BranLiang?source=rss-75b355950f1f------2</link>
        <image>
            <url>https://cdn-images-1.medium.com/fit/c/150/150/1*qwYKzC6MV2cidHgFFNt6WA.jpeg</url>
            <title>Stories by liang boyuan on Medium</title>
            <link>https://medium.com/@BranLiang?source=rss-75b355950f1f------2</link>
        </image>
        <generator>Medium</generator>
        <lastBuildDate>Mon, 23 Nov 2026 08:06:02 GMT</lastBuildDate>
        <atom:link href="https://medium.com/@BranLiang/feed" rel="self" type="application/rss+xml"/>
        <webMaster><![CDATA[yourfriends@medium.com]]></webMaster>
        <atom:link href="http://medium.superfeedr.com/" rel="hub"/>
        <item>
            <title><![CDATA[A complete guide to webrtc with Ruby on Rails]]></title>
            <link>https://medium.com/@BranLiang/a-complete-guide-to-webrtc-with-ruby-on-rails-9ea68e67154e?source=rss-75b355950f1f------2</link>
            <guid isPermaLink="false">https://medium.com/p/9ea68e67154e</guid>
            <category><![CDATA[webrtc]]></category>
            <category><![CDATA[ruby-on-rails]]></category>
            <dc:creator><![CDATA[liang boyuan]]></dc:creator>
            <pubDate>Wed, 29 Apr 2020 13:50:48 GMT</pubDate>
            <atom:updated>2020-04-29T13:50:48.881Z</atom:updated>
            <content:encoded><![CDATA[<p>A complete guide to webrtc with Ruby on Rails</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/820/1*5D85FyNwi0mIfd-eZl0ioQ.png" /></figure><p>First time to implement webrtc? Having trouble with signal server? Struggling to figure out what actually is going on with webrtc? Or you are just curious how I managed to build a webrtc server with Ruby on Rails. Then this is the place, keep reading!</p><p>First of all. Let’s forget about detail code implementation, let’s discuss the theory behind the webrtc and see why they are not that <strong>difficult</strong> actually.</p><h3>What I am going to do?</h3><p>This is the first question you should ask you self. So, generally, you want to talk to another person on the internet. In this case, Bran wants to talk to Alan. But in no way could Bran know where the hack is Alan now for the moment.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/716/1*pG-MJjy6EKroJAYpCysgjQ.png" /><figcaption>Bran wants to talk to Alan</figcaption></figure><h3>Please tell me where are you!</h3><p>So, in order to find the position of Alan and also broadcast self information. A server which trusted by both parties should be created. That is the so called <strong>signaling server</strong> in the webrtc world.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/661/1*AbicZP3kIWxxSokielrYig.png" /><figcaption>Happy family!</figcaption></figure><p>With signaling server, nodes connected to that can exchange information. And in this case, Bran can send message to Alan, and Alan can reply to Bran. In webrtc world and also professionally, Bran needs to get its <strong>LocalDescription </strong>and send it to Alan, and Alan needs to send its <strong>LocalDescription </strong>to Bran, both should take the other’s description as <strong>RemoteDescription</strong></p><p>Theoretically, that should be enough for Bran and Alan to talk to each other now. However, in real world, that’s still not enough. Because, not everyone on the internet has IP address. And there probably will be dozens of proxy layers sit in between.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/766/1*LD0k-2C1FpyaQ-29UBMXRQ.png" /><figcaption>It’s such a long way to go Surfing!</figcaption></figure><p>So, another hero <strong>iceServer </strong>is<strong> </strong>here to help. The main ability for it is to help you find real IP address behind proxy wall. In this case both Bran and Alan should connect to iceServer and get its connecting method and send to each other. Like the illustration below.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/697/1*gwD83UPKdRYP2s_93ZZy8Q.png" /></figure><p>Basically, that all you need to do to setup connection between two nodes</p><p>Next, I will show you the demo I build with ruby on rails and discuss a little bit about that. If you want to explore the demo codebase directly, here is link <a href="https://github.com/BranLiang/demo-rails-webrtc">https://github.com/BranLiang/demo-rails-webrtc</a></p><h3>Demo showcase</h3><p><a href="https://demo-rails-webrtc.herokuapp.com/">https://demo-rails-webrtc.herokuapp.com/</a></p><figure><img alt="" src="https://cdn-images-1.medium.com/max/640/1*DJljliMTU4lJLVBdozff-g.gif" /></figure><p>Usage for the demo can be found on Github project.</p><h3>Code Explain</h3><p>The signaling server used for this project is ActionCable, it is install by default with ruby on rails, one thing tricky is that you can not send message from server to specific user, you can only broadcast to all users in the channel. If you find otherwise, please do let me know!</p><p>For JS interaction part, framework <a href="https://stimulusjs.org/">stimulus</a> is used. Which is HTML unlike React or Vue. I like them all, just picked this one by random.</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/b71fc93e7a72bdbd38a2e3a030c4555f/href">https://medium.com/media/b71fc93e7a72bdbd38a2e3a030c4555f/href</a></iframe><p>Above is the main Connector class created to support webrtc connection. You can follow my code and take a try. One thing to mention is that you should add <strong>ICE candidate</strong> after getting both side descriptions.</p><h3>Conclusion</h3><p>Webrtc is powerful, this demo only shows how to do video conference, but it can do more! Take a try and have fun! Cheers!</p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=9ea68e67154e" width="1" height="1" alt="">]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[Build your first gRPC demo with ruby]]></title>
            <link>https://medium.com/@BranLiang/build-your-first-grpc-demo-with-ruby-12fba2c90a67?source=rss-75b355950f1f------2</link>
            <guid isPermaLink="false">https://medium.com/p/12fba2c90a67</guid>
            <category><![CDATA[ruby]]></category>
            <category><![CDATA[demo]]></category>
            <category><![CDATA[grpc]]></category>
            <dc:creator><![CDATA[liang boyuan]]></dc:creator>
            <pubDate>Sat, 21 Mar 2020 07:42:45 GMT</pubDate>
            <atom:updated>2020-03-21T07:42:45.645Z</atom:updated>
            <content:encoded><![CDATA[<figure><img alt="" src="https://cdn-images-1.medium.com/max/1000/0*YhanHNlpV0KNBgN-.png" /></figure><p>I have heard about gRPC for a while but what is it? And how can I use this new fancy technology with Ruby? If you also have whose questions, then just follow the article and you will find answers!</p><p>Related source code for this article: <a href="https://github.com/BranLiang/grpc-ruby-demo">https://github.com/BranLiang/grpc-ruby-demo</a></p><p>First of all, I think you already checked the <a href="https://github.com/grpc/grpc">official gRPC repository </a>, and their official <a href="https://grpc.io/docs/quickstart/ruby/">documentations</a> for ruby. However, in order to follow that quick start, you should clone all their example code, which covers a lot of different language, what if I just want to use ruby and start from scratch? Here I am, we will start from zero and until the last. At the end, I will conclude my thoughts about this new fancy tools.</p><p>Let’s start with an empty folder with only Gemfile. Then bundle installall necessary packages. Among them, grpcis used in code, and grpc-toolsis used for so called protocal buffer compile.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*5TZMdzsI2j9OrwOUNcpqAQ.png" /></figure><p>Then, you need a proto file to define your interfaces, which means you need to decide what kind communications can be made across your services. <strong><em>This file should be shared between client and server</em></strong>, so they can understand each other.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*V4nttQBFZKpKgTS2ov_pbA.png" /></figure><p>After function definitions, ruby language adapter should be generated, so you can use those defined functions in ruby. Also, if you don’t use ruby, you can also generate other language adapter files. The command is as follow.</p><pre>$ mkdir lib<br>$ grpc_tools_ruby_protoc --ruby_out=lib --grpc_out=lib ./helloworld.proto</pre><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*YDhCQUkf9tgptqpKS8eiXQ.png" /></figure><p>You should now see two new generated files, and like the comment says, <strong><em>DO NOT EDIT</em></strong> them.</p><p>Next step, we should create a server that can respond to client. There is one trick with $LOAD_PATH . The first line there enables you to require files in lib folder. And the server is pretty simple, with only one hander.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*O35zfdHxgwHVzHZBvqnBLQ.png" /></figure><p>Now, you can start your first gRPC server, with following command, be sure to call that on project root path. Not in the server folder.</p><pre>$ ruby ./server/server.rb</pre><p>Last, create a simple client which can call server.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*tZr2MMKgO5w1TiD5Haq6rQ.png" /></figure><pre>$ ruby client/client.rb</pre><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*DomsSvWv-NZV7wPvMCORKw.png" /></figure><p>You should see responses from terminal now.</p><p>The demo is finished here. But we should think back about gRPC. There is one advantage for it, we can keep the client up to date with server changes easily, every time, you add a new interface or change the interface on server, you will change the proto file. Then if you want the client to update with server, you can simply copy the proto file to the client code base and run the adapter generate command. That’ it for the client code base update.</p><p>Compared with http protocal and REST way, my opinion is gRPC way is much easier to manage the interface. However, the community is still pretty early stage for gRPC, especially for ruby, so think carefully if you really want to adopt gRPC.</p><p>Cheers!</p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=12fba2c90a67" width="1" height="1" alt="">]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[Lambda with Canary Deploy]]></title>
            <link>https://medium.com/@BranLiang/lambda-with-canary-deploy-83572dfcf871?source=rss-75b355950f1f------2</link>
            <guid isPermaLink="false">https://medium.com/p/83572dfcf871</guid>
            <category><![CDATA[lambda]]></category>
            <category><![CDATA[canary-deployments]]></category>
            <category><![CDATA[codedeploy]]></category>
            <category><![CDATA[aws]]></category>
            <dc:creator><![CDATA[liang boyuan]]></dc:creator>
            <pubDate>Wed, 30 Oct 2019 09:15:34 GMT</pubDate>
            <atom:updated>2019-10-30T09:15:34.126Z</atom:updated>
            <content:encoded><![CDATA[<figure><img alt="" src="https://cdn-images-1.medium.com/max/800/1*uqDt6kys_zWRNiDTVjDmsg.png" /><figcaption>canary deploy</figcaption></figure><p>With <a href="https://serverless.com/">serverless framework</a>, you can easily deploy your function to your cloud. But what if you want to canary deploy the lambda? Here is the <strong>simplest</strong> solution you could ever find on the internet. Trust me, I already googled a lot and all solutions on the internet are too complex to finish.</p><h4>Advantages</h4><ul><li>No plugin used, <a href="https://github.com/davidgf/serverless-plugin-canary-deployments">https://github.com/davidgf/serverless-plugin-canary-deployments</a> this is the plugin you probably will found on Github. it is complex and has many limitations, you are welcome to take a try on that, or just use my solution.</li><li>No AWS codedeploy pipeline needed, codedeploy for canary is just way too difficult, especially for those who are not familiar with that tool.</li></ul><h4>Theory behind</h4><p>Your trigger is on your alias, not on your function anymore. And every time you deploy your code. You manually update the version and weight for each version. So everything is under control.</p><h4>Walk through</h4><p><strong>Step 1</strong></p><p>Prepare an your project, so that you can deploy that to lambda. I will not explain how to do that as you could find plenty way to achieve that.</p><p><strong>Step 2</strong></p><p>Create an alias for your function. Which I would name it <strong>current.</strong></p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1002/1*fEomMANcuyxBVV2BovYC_A.png" /></figure><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*5o-RCJ2j8xNq8Xcd7_N3Gw.png" /></figure><p><strong>Step 3</strong></p><p>After step 2, you will get your aliased function. Now attach the trigger to your alias like you would do to your lambda.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*VrCBP1YgB7YFBQz2YldgVQ.png" /></figure><p><strong>Step 4</strong></p><p>Now that’s pretty it. Now every time you do deploy. You lambda will not be effective immediately. You should go to your current alias and update the version and weight manually.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*x3Cim0OwfO1jURBtBGoSwA.png" /></figure><h4>Done! Easy and simple!</h4><p>Leave a message if you have any question.</p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=83572dfcf871" width="1" height="1" alt="">]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[Guidance on AWS lambda in Ruby]]></title>
            <link>https://medium.com/@BranLiang/guidance-on-aws-lambda-in-ruby-c59805c591ee?source=rss-75b355950f1f------2</link>
            <guid isPermaLink="false">https://medium.com/p/c59805c591ee</guid>
            <category><![CDATA[aws]]></category>
            <category><![CDATA[ruby]]></category>
            <category><![CDATA[lambda]]></category>
            <dc:creator><![CDATA[liang boyuan]]></dc:creator>
            <pubDate>Thu, 13 Dec 2018 13:13:32 GMT</pubDate>
            <atom:updated>2018-12-13T13:13:32.938Z</atom:updated>
            <content:encoded><![CDATA[<figure><img alt="" src="https://cdn-images-1.medium.com/max/850/1*OIZizaxl-1CA3mZZOeHSOQ.jpeg" /></figure><p>Recently amazon announced official support for AWS lambda Ruby. If you want to try a lambda function in ruby and don’t know how to get start. This is the article for you.</p><h3>Prerequisite</h3><ul><li>Ruby 2.5.0(Official supported ruby version by aws)</li><li>Sam(aws serverless function command line tool)</li><li>Docker(For local lambda function test)</li><li>aws(aws command line tool, which integrate nicely with sam)</li></ul><p>These are the tools needed. After all the tools are installed, please configured your aws, which will gives you credentials for further.</p><pre># check if you have properly configured<br>aws configure</pre><h3>Bootstrap</h3><pre>sam init --runtime ruby2.5</pre><p>This is a skeleton command offered by sam which gives you a pretty nice preconfigured project template. I highly recommend read through the readme file generated by the command. After that you will grasp a basic idea on how to properly arrange your code and tests.</p><h3>Configuration</h3><p>After bootstrapping, the next step is to config you function. All the configuration lies on the file template.yaml . Normally, you will configure the CodeUri, Handler, MemorySize, Role . For the complete reference, the official sam documentation is recommended. <a href="https://github.com/awslabs/serverless-application-model/blob/master/versions/2016-10-31.md">https://github.com/awslabs/serverless-application-model/blob/master/versions/2016-10-31.md</a></p><h3>Deploy</h3><p>The deploy process includes step steps.</p><ul><li>Install dependencies by bundle install --deployment</li><li>Package your project</li><li>Deploy the project with aws formation</li></ul><p>From my personal practice, I created a deploy.sh for convenient.</p><pre>echo &#39;<em>Install dependencies...</em>&#39;</pre><pre>bundle install --without development test --deployment --path hello_world/vendor/bundle</pre><pre>echo &#39;<em>Packaging...</em>&#39;</pre><pre>sam package --template-file template.yaml --output-template-file packaged.yaml --s3-bucket feedmob-lambda-packages</pre><pre>echo &#39;<em>Deploying...</em>&#39;</pre><pre>sam deploy --template-file packaged.yaml --stack-name loadbalance-redshift-ruby-lambda --capabilities CAPABILITY_IAM</pre><h3>Traps</h3><p>This is a mini project which should work properly. However if you want to implement more complex project which relates to gems having native extensions. The problem will rise, as the base environment offered by aws just don’t have necessary dependencies. I have tried to use pg in my project. But after countless tries, still no luck for. The most promising article found on line is this one. <a href="https://www.reddit.com/r/ruby/comments/a3e7a1/postgresql_on_aws_lambda_ruby/">https://www.reddit.com/r/ruby/comments/a3e7a1/postgresql_on_aws_lambda_ruby/</a> Take a try if you think you can manage it.</p><h3>Conclusion</h3><p>Have fun on lambda ruby ^_^</p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=c59805c591ee" width="1" height="1" alt="">]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[Step by step to setup continues deployment Kubernetes on AWS with EKS, Code pipeline and lambda]]></title>
            <link>https://medium.com/@BranLiang/step-by-step-to-setup-continues-deployment-kubernetes-on-aws-with-eks-code-pipeline-and-lambda-61136c84bbcd?source=rss-75b355950f1f------2</link>
            <guid isPermaLink="false">https://medium.com/p/61136c84bbcd</guid>
            <category><![CDATA[aws-lambda]]></category>
            <category><![CDATA[kubernetes]]></category>
            <category><![CDATA[aws]]></category>
            <category><![CDATA[continuous-deployment]]></category>
            <category><![CDATA[docker]]></category>
            <dc:creator><![CDATA[liang boyuan]]></dc:creator>
            <pubDate>Thu, 11 Oct 2018 06:25:39 GMT</pubDate>
            <atom:updated>2018-10-11T06:48:38.974Z</atom:updated>
            <content:encoded><![CDATA[<figure><img alt="" src="https://cdn-images-1.medium.com/max/800/1*Yv6fat4zVvnEDPbOv18jvQ.png" /></figure><p>This article meant to be a guidance to help you setup kuberneters on aws. And it also assume that you love the feeeling of continues deployment.</p><p>Prerequisite for the following content reading:<br>1. Familiar with AWS dashboard and used it for sometime.<br>2. Basic docker concept<br>3. Basic nodejs knowledge</p><p>Before the real deal comes. First ask a question for your self, do I really need kubernetes? Because although kubernetes is awesome, it also comes with great complex. So if your application is simple and only require few server machine setups, this guide may also not suitable for you, I suggest you could try just ECS on AWS or other similar services.</p><p>If your answer is yes or you just however want to taste kubernetes. Here I am! The first step you need to setup the cluster on aws. Find the eks service as the following picture.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/771/1*6aAib2LsSHjdZk8eiAus7A.png" /></figure><p>Make sure you have all the permission to create a cluster and also be aware of that the cluster will charge you 0.2$ per hour. If you don’t need it anymore, don’t forget to delete after.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/951/1*1iCGR0h4Q8sdmQ7N_0CioA.png" /></figure><p>Input your configuration for the cluster. If you don’t have the IAM role created for the eks or the VPC has not been created. Setup them first, these steps are simple, I will assume that you can finish them without any problems. After the creation of cluster you will see the cluster listed in your eks dashboard.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*Rn7cBdMHfEDh7jkBKO1WKQ.png" /></figure><p>Now your cluster is ready, but because there are no workers linked to your cluster yet. You can’t really deploy anything for the moment. So next step is to link some node workers for your newly created cluster. Follow the guide provided by aws <a href="https://docs.aws.amazon.com/eks/latest/userguide/getting-started.html">https://docs.aws.amazon.com/eks/latest/userguide/getting-started.html</a><br>Just be aware that its better to use the AMI provided by the guide, as these machines are preconfigured. You could skip the step 4 here. After the guide you should have your cluster settled with some node workers. Check them with the following commands.</p><pre>kubectl get nodes</pre><p>You should see some nodes listed there. Now it’s time to deploy an application. I will use a bootstrapped Rails application as an example here. The application is hosted <a href="https://github.com/BranLiang/eks-demo/tree/stage">here</a> . Stage branch is used, as normally you will always want to deploy to stage first before push you commit to the master.<br>(You could also try manually deploy the application without the help of the code pipeline)</p><pre><em>FROM</em> ruby:2.5.1</pre><pre><em>ENV</em> APP_PATH /app</pre><pre>#<em> Install basic dependencies</em></pre><pre><em>RUN</em> curl -sL https://deb.nodesource.com/setup_8.x | bash</pre><pre><em>RUN</em> apt-get update -qq &amp;&amp; apt-get install -y --no-install-recommends apt-utils build-essential libpq-dev nodejs</pre><pre><em>RUN</em> npm install -g yarn</pre><pre><em>RUN</em> mkdir $APP_PATH</pre><pre><em>WORKDIR</em> $APP_PATH</pre><pre><em>COPY</em> Gemfile /$APP_PATH/Gemfile</pre><pre><em>COPY</em> Gemfile.lock /$APP_PATH/Gemfile.lock</pre><pre>#<em> Install gemfiles</em></pre><pre><em>RUN</em> bundle install</pre><pre>#<em> Bundle app source code</em></pre><pre><em>COPY</em> . .</pre><pre>#<em> Asset precompile</em></pre><pre><em>RUN</em> bundle exec rake assets:precompile</pre><pre><em>CMD</em> [<em>&quot;bundle&quot;</em>, <em>&quot;exec&quot;</em>, <em>&quot;rails&quot;</em>, <em>&quot;s&quot;</em>]</pre><p>This is a basic dockerfile, you could define any dockerfile you want for your application. And this is also the beauty for docker. As the deployment process is unified to the dockerfile.</p><pre><em>version</em>: 0.2</pre><pre><em>phases</em>:</pre><pre><em>pre_build</em>:</pre><pre><em>commands</em>:</pre><pre>- <em>echo Logging in to Amazon ECR...</em></pre><pre>- <em>$(aws ecr get-login --no-include-email --region $AWS_DEFAULT_REGION)</em></pre><pre><em>build</em>:</pre><pre><em>commands</em>:</pre><pre>- <em>echo Build started on `date`</em></pre><pre>- <em>echo Building the Docker image...</em></pre><pre>- <em>CUSTOM_TAG=$(date +%s)</em></pre><pre>- <em>docker build -t $IMAGE_REPO_NAME:$CUSTOM_TAG .</em></pre><pre>- <em>docker tag $IMAGE_REPO_NAME:$CUSTOM_TAG $AWS_ACCOUNT_ID.dkr.ecr.$AWS_DEFAULT_REGION.amazonaws.com/$IMAGE_REPO_NAME:$CUSTOM_TAG</em></pre><pre><em>post_build</em>:</pre><pre><em>commands</em>:</pre><pre>- <em>echo Build completed on `date`</em></pre><pre>- <em>echo Pushing the Docker image...</em></pre><pre>- <em>docker push $AWS_ACCOUNT_ID.dkr.ecr.$AWS_DEFAULT_REGION.amazonaws.com/$IMAGE_REPO_NAME:$CUSTOM_TAG</em></pre><p>Also a buildspec is defined, the thing need to notice here is that the image tag is not static, it is the timestamp in seconds. Actually, at the beginning, the image tag is static and it is always set to latest , however when thinking about the deployment, static image tag means static image uri. Kubernetes will think the image is not changed, so the update will have problem. Also if you need rollback, because the preview image tag has no tags now, the rollback will also be difficult. You could also use hashing or other method to generate you tags.</p><p>Now the project is ready for deployment. Let’s create the code pipeline.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/753/1*Hj7JPkeT28dF1AKPvMxQ4Q.png" /></figure><p>First step for pipeline is simple, just choose a trigger and that is probably github, authorize aws the access to your repository and that probably is done.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/606/1*NLWeqsbkYTSBZ3WGcqTmFA.png" /></figure><p>Next step is to create a code build which will build the docker image according to your github repository. The build spec has already been written in the code repository. Here are the sample of my code build.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/613/1*AUt0gdtNOMTVTAmm2dOAgg.png" /></figure><figure><img alt="" src="https://cdn-images-1.medium.com/max/731/1*isKjzutsdiKykKhPj0JiXg.png" /></figure><p>Be careful, don’t forget to set build env in your code build step</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/406/1*_Qw7qDoeKCUw4KVu4o_8pQ.png" /></figure><p>Now, you should has two steps for your code pipeline. And you can try it your self to update the code and push it to stage branch. You should see new image build in ECR like follows.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/866/1*TwCQ5Y_FjN0-vFr6x0HIag.png" /></figure><p>After the build step, you have the docker image and you also have the kubernetes cluster settled. You want to deploy the image or update the existing deployment with the newly created docker image. But how? There is no build-in module in aws code pipeline which can help you to achieve that easily. So you googled and find this following link and illustration</p><p><a href="https://aws.amazon.com/blogs/devops/continuous-deployment-to-kubernetes-using-aws-codepipeline-aws-codecommit-aws-codebuild-amazon-ecr-and-aws-lambda/">Continuous Deployment to Kubernetes using AWS CodePipeline, AWS CodeCommit, AWS CodeBuild, Amazon ECR and AWS Lambda | Amazon Web Services</a></p><figure><img alt="" src="https://cdn-images-1.medium.com/max/975/1*IZrZ7kX4oYkHS1-H9obp-Q.png" /></figure><p>AWS tells you that you can use lambda to deploy your kubernetes and that’s all. But no one tells your how to write your lamda, don’t worry. I am here to help. Before showing you my way, you could also check the link below to see how aws config the aws-kube-lambda.</p><p><a href="https://github.com/aws-samples/aws-kube-codesuite/blob/master/src/kube-lambda.py">aws-samples/aws-kube-codesuite</a></p><p>This link above doesn’t work for me. As I just couldn’t know how to get the client_cert and client_key for kubernetes configuration. After countless tries, I found that you don’t need client_cert or client_key at all. According to the link <a href="https://github.com/StevenACoffman/eks-deployer-lambda">https://github.com/StevenACoffman/eks-deployer-lambda</a> all you need for kubernetes authentication are 1. Cluster Certificate Authority Data 2. Your cluster host 3. bearer token.</p><p>To get cluster certificate authority data</p><pre>aws eks describe-cluster --region us-east-1 --name $CLUSTERNAME --query cluster.certificateAuthority.data</pre><p>To get your cluster host address</p><pre>aws eks describe-cluster --region us-east-1 --name $CLUSTERNAME --query cluster.endpoint</pre><p>To get your bearer token, first get your secrets name</p><pre>kubectl get secrets</pre><p>Then run the following command to get your token</p><pre>kubectl get secret $SECRET_NAME -o json | jq -r &#39;.data[&quot;token&quot;]&#39; | base64 -D</pre><p>After getting all the values, you are ready to config your kubernetes client on lambda. The example here will use official kubernetes js client. Full code is in the <a href="https://github.com/BranLiang/lambda-eks">repo</a> .</p><pre>apiVersion: v1</pre><pre>clusters:</pre><pre>- cluster:</pre><pre>certificate-authority-data: $EKS_CA</pre><pre>server: $EKS_CLUSTER_HOST</pre><pre>name: $EKS_CLUSTER_NAME</pre><pre>contexts:</pre><pre>- context:</pre><pre>cluster: $EKS_CLUSTER_NAME</pre><pre>namespace: default</pre><pre>user: $EKS_CLUSTER_USER_NAME</pre><pre>name: $EKS_CLUSTER_USER_NAME</pre><pre>current-context: $EKS_CLUSTER_USER_NAME</pre><pre>kind: Config</pre><pre>preferences: {}</pre><pre>users:</pre><pre>- name: $EKS_CLUSTER_USER_NAME</pre><pre>user:</pre><pre>token: $TOKEN</pre><p>Input the token and data you get from the previews step. Then you can initialize the kubernetes client as follows</p><pre><em>const</em> k8s = require(&#39;<em>@kubernetes/client-node</em>&#39;);</pre><pre><em>const</em> kc = <em>new</em> k8s.KubeConfig();</pre><pre><em>const</em> fs = require(&#39;<em>fs</em>&#39;)</pre><pre><em>var</em> raw = fs.readFileSync(&#39;<em>./config</em>&#39;, &#39;<em>utf8</em>&#39;)</pre><pre>/*<em> Input values </em>*/</pre><pre>raw = raw.replace(/<em>\$TOKEN</em>/<em>g</em>, process.env.EKS_TOKEN)</pre><pre>raw = raw.replace(/<em>\$EKS_CA</em>/<em>g</em>, process.env.EKS_CA)</pre><pre>raw = raw.replace(/<em>\$EKS_CLUSTER_HOST</em>/<em>g</em>, process.env.EKS_CLUSTER_HOST)</pre><pre>raw = raw.replace(/<em>\$EKS_CLUSTER_NAME</em>/<em>g</em>, process.env.EKS_CLUSTER_NAME)</pre><pre>raw = raw.replace(/<em>\$EKS_CLUSTER_USER_NAME</em>/<em>g</em>, process.env.EKS_CLUSTER_USER_NAME)</pre><pre>kc.loadFromString(raw)</pre><pre>module.exports = kc</pre><p>Check my <a href="https://github.com/BranLiang/lambda-eks">code_repo</a> for detailed implementation. For the moment there is no documentation for kubernetes nodejs client. So you could just check the source code and find the implementation methods. My script will first get the latest deployment image uri and then create a new deployment or just replace the deployment image.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/772/1*-5JAjvlMih_-U4TKzlpBgw.png" /></figure><p>Be sure that you fill in all the env on your lambda function. Now add the final deploy step for your code pipeline.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/602/1*q9ALRJu9K1Jza1ekYA0J_w.png" /></figure><p>The parameter need to be careful is user parameter. The value here will your deployment name as well as the docker image name.</p><p>Now change your repo code and push it to the github. You will see the application change after several minutes automatically. What a magic! Leave the deployment and scaling job to kubernetes, let us just care about the core code.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/273/1*uXRhZhKn_woJBKp_2GbSgg.png" /></figure><p>If you have any problem with continues deployment kubernetes on aws. Star my project <a href="https://github.com/BranLiang/lambda-eks">https://github.com/BranLiang/lambda-eks</a> and post issues there. I will be very happy to help. Cheers!</p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=61136c84bbcd" width="1" height="1" alt="">]]></content:encoded>
        </item>
    </channel>
</rss>