title: How to dynamically create an inline Lambda with AWS SDK for JavaScript?
body: <p>I need to create a simple Lambda programmatically from another Lambda.</p>
  
  <p>This is possible with CloudFormation:</p>
  
  <pre><code>MyLambda:
    Type: AWS::Lambda::Function
    Properties:
      FunctionName: my-lambda
      Handler: index.handler
      Runtime: nodejs8.10
      Role: !GetAtt MyRole.Arn
      Code:
        ZipFile: &gt;
          exports.handler = event =&gt; console.log('EVENT', event)
  </code></pre>
  
  <p>I want to create a Lambda in the same manner programmatically. </p>
  
  <p>When I pack the Lambda code into a zip file and upload the zip with the Lambda code, everything works fine:</p>
  
  <pre><code>const lambda = new Lambda({apiVersion: '2015-03-31'});
  ...
  await lambda.createFunction({
      FunctionName: 'my-lambda',
      Handler: 'index.handler',
      Runtime: 'nodejs8.10',
      Role: role.Role.Arn,
      Code: {
          ZipFile: fs.readFileSync('my-lambda.zip')
      }
  }).promise();
  </code></pre>
  
  <p>But it is a lot of boilerplate code to write Lambda code into a file and zip it afterwards.</p>
  
  <p>If I try to set the Lambda code inline:</p>
  
  <pre><code>...
  Code: {
      ZipFile: "exports.handler = event =&gt; console.log('EVENT', event)"
  }
  </code></pre>
  
  <p>I get an expected error:</p>
  
  <blockquote>
    <p>Failed: Could not unzip uploaded file. Please check your file, then try to upload again.</p>
  </blockquote>
  
  <p>Is there a way <strong>how to create an inline Lambda function from another Lambda dynamically</strong>, similar to the CloudFormation "hack" mentioned on the top?   </p>
  
  <p><strong>EDIT:</strong> Focus of the question on dynamical creation of code without need to zip it first.</p>