title: AWS codeBuild/codePipeline with serverless framework
body: <p>I am trying to automate <strong>Deployment Pipeline</strong> for my application. Here is the automation architecture, I came up with:
  <a href="https://i.stack.imgur.com/Hpjjt.png" rel="noreferrer"><img src="https://i.stack.imgur.com/Hpjjt.png" alt="Automation Architecture"></a></p>
  
  <p>As you can see, I am using <strong>codePipeline</strong> and <strong>codeBuild</strong> to automate my deployment. My backend is based on <a href="https://serverless.com/" rel="noreferrer">Serverless Framework</a>, which deploys lambda functions on firing <code>sls deploy</code> command. This is the reason, I did not use <strong>codeDeploy</strong> to do traditional deployment. <code>buildspec.yml</code> file looks like this:</p>
  
  <pre><code>version: 0.1
  
  phases:
    install:
      commands:
        – apt-get -y update
        – npm install -g serverless@1.9.0
    build:
      commands:
        – cd nj2jp/serverless &amp;&amp; npm install
    post_build:
      commands:
        – serverless deploy –verbose
  
  artifacts:
    files:
      – serverless.yml
    discard-paths: yes
  </code></pre>
  
  <p>Now, I have <strong>3 Questions</strong> in regards to <strong>CodeBuild</strong> and <strong>Serverless</strong>: </p>
  
  <p><strong>Question 1:</strong> The command <code>sls deploy</code> depends on a file called <code>config.yml</code> which contains secrets such as db password. This file will not be checked into git. What do you think is the best possible way to include <code>config.yml</code> in codeBuild?</p>
  
  <p><strong>Question 2:</strong> <strong>Rollbacks</strong> can be done with AWS, if we have to deploy traditional EC2 applications using <strong>codeDeploy</strong>. In case of serverless, we are not using <strong>codeDeploy</strong> and serverless also supports <strong>rollback</strong> features. How do we leverage serverless rollback within the <strong>codePipeline</strong>?</p>
  
  <p><strong>Question 3:</strong> Triggering codePipeline when a <strong>Pull Request</strong> happens. I saw some posts saying, it is not supported by codePipeline. But those posts were from last year, Is Pull Request now supported by codePipeline? </p>
  
  <p><strong>Hack Answers</strong>(Not correct, but works. Need better answers from you.)</p>
  
  <p><strong>Answer 1:</strong> The <code>config.yml</code> file can be saved in a private <strong>S3 bucket</strong> and can be pulled to codeBuild as part of <code>pre-build</code> setup or We can add all secrets to codeBuild's Env variables. I dont like the second option, as I want to have  consistent across all environments. Any better solutions for this problem?</p>
  
  <p><strong>Answer 2:</strong> I cannot think of an hack for this. Looking out for answers from you.</p>
  
  <p><strong>Answer 3:</strong> I came across some blog posts that use <a href="https://nicolai86.eu/blog/posts/2017-03-25/awesome-aws-codepipeline-ci/" rel="noreferrer">[APIGateway + Lambda + S3]</a> to trigger <strong>codePipeline</strong> for pull requests. But I feel, this feature has to be provided as an out-of-box one. Is there any updates on the codePipeline for this feature?</p>