title: How to increase memory available for chromium in chrome-aws-lambda?
body: <p>I collect the data using puppeteer and chrome-aws-lambda. I plan to push it to AWS Lambda but while testing locally I get an error:</p>
  <pre><code>Error: Protocol error (Runtime.callFunctionOn): Target closed.
  </code></pre>
  <p>when I call for <code>waitForSelector</code>.</p>
  <p>I've some posts that mentioned there is a chance that chrome process gets too little memory within the docker. The question is: how to get it more memory? I also read that <code>disable-dev-shm-usage</code> may help, but it doesn't. That's how I do it now (the last line is where error happens):</p>
  <pre><code>const chromium = require('chrome-aws-lambda');
  browser = await chromium.puppeteer.launch({
              args: [...chromium.args, `--proxy-server=${proxyUrl}`, '--disable-dev-shm-usage'],
              defaultViewport: chromium.defaultViewport,
              executablePath: await chromium.executablePath,
              headless: chromium.headless,
              ignoreHTTPSErrors: true,
          });
          const page = await browser.newPage();
  
          await page.authenticate({ username, password });
          await page.goto(MY_URL, { waitUntil: 'domcontentloaded' })
          await page.click(SUBMIT_SELECTOR);
          await page.waitForSelector('#myDiv')
              .then(() =&gt; console.log('got it')).
              catch((e)=&gt;console.log('Error happens: '+ e));
  
  </code></pre>
  <p>UPDATE: more info on local setup:</p>
  <p>I run it locally using <code>sam local start-api</code>.
  Here is the content of my <code>template.yaml</code> (just a slightly updated <code>hello-world</code> template:</p>
  <pre class="lang-yaml prettyprint-override"><code>AWSTemplateFormatVersion: '2010-09-09'
  Transform: AWS::Serverless-2016-10-31
  Description: &gt;
    samnode
  
    Sample SAM Template for samnode
    
  # More info about Globals: https://github.com/awslabs/serverless-application-model/blob/master/docs/globals.rst
  Globals:
    Function:
      Timeout: 60
  
  Resources:
    
    HelloWorldFunction:
      Type: AWS::Serverless::Function # More info about Function Resource: https://github.com/awslabs/serverless-application-model/blob/master/versions/2016-10-31.md#awsserverlessfunction
      Properties:
        CodeUri: hello-world/
        Handler: app.lambdaHandler
        Runtime: nodejs14.x
        MemorySize: 4096
        Layers:
          - !Sub 'arn:aws:lambda:${AWS::Region}:764866452798:layer:chrome-aws-lambda:22'
        Events:
          HelloWorld:
            Type: Api # More info about API Event Source: https://github.com/awslabs/serverless-application-model/blob/master/versions/2016-10-31.md#api
            Properties:
              Path: /hello
              Method: get
  
  Outputs:
    # ServerlessRestApi is an implicit API created out of Events key under Serverless::Function
    # Find out more about other implicit resources you can reference within SAM
    # https://github.com/awslabs/serverless-application-model/blob/master/docs/internals/generated_resources.rst#api
    HelloWorldApi:
      Description: &quot;API Gateway endpoint URL for Prod stage for Hello World function&quot;
      Value: !Sub &quot;https://${ServerlessRestApi}.execute-api.${AWS::Region}.amazonaws.com/Prod/hello/&quot;
    HelloWorldFunction:
      Description: &quot;Hello World Lambda Function ARN&quot;
      Value: !GetAtt HelloWorldFunction.Arn
    HelloWorldFunctionIamRole:
      Description: &quot;Implicit IAM Role created for Hello World function&quot;
      Value: !GetAtt HelloWorldFunctionRole.Arn
  
  </code></pre>