title: How can AWS CloudFormation pull code from Git?
body: <p>I have source-code that lives in a Git repo (GitHub). I have several branches for different environments (e.g. <code>develop</code>, <code>production</code>) and I prefer to manage releases inside the GitHub interface using protected branches. </p>
  
  <p>I want a push to a branch to trigger tests and deployment. </p>
  
  <p>However, I also use CloudFormation to deploy AWS services in a reproducible way. My problem is in interfacing CloudFormation with my Git process. </p>
  
  <p>For example, AWS Lambda functions are described in CloudFormation templates like this: </p>
  
  <pre><code>{
    "Type" : "AWS::Lambda::Function",
    "Properties" : {
      "Code": "source code here"
    }
  }
  </code></pre>
  
  <p>... where <code>Code</code> is "Amazon Simple Storage Service (Amazon S3) bucket or specify your source code as inline text. " (<a href="https://docs.aws.amazon.com/AWSCloudFormation/latest/UserGuide/aws-resource-lambda-function.html#cfn-lambda-function-code" rel="noreferrer">Docs</a>)</p>
  
  <p>This means I need to do a manual step after deploying my CloudFormation template: </p>
  
  <ul>
  <li>Checkout the latest AWS Lambda code from <code>$BRANCH</code> at <code>$REPO</code></li>
  <li>Run any tests</li>
  <li>Run my build &amp; package script</li>
  <li>Upload the code to AWS Lambda</li>
  </ul>
  
  <p><em>(This can be done in a CI provider, but then I still have to click "Rebuild" on each repo)</em></p>
  
  <p>What I would rather do is define my CI pipeline <em>inside</em> the CloudFormation template. This should be possible using EC2 etc, but I don't know how. The Git repo URL would then be a parameter of the CloudFormation template. </p>
  
  <p><strong>How do I define Git hooks, build steps and deployment in a CloudFormation template?</strong> The steps should also run as part of a fresh CloudFormation deployment. </p>