title: How to reuse Layers on AWS both locally using SAM and when they're deployed?
body: <p>So far I have this <code>template.yml</code>:</p>
  <pre><code>AWSTemplateFormatVersion: '2010-09-09'
  Transform: AWS::Serverless-2016-10-31
  Description: &gt;
    My Lambda for doing something
  
  Resources:
    FirstLayer:
      Type: AWS::Serverless::LayerVersion
      Properties:
        LayerName: FirstLayer
        Description: First layer of dependencies
        ContentUri: layers/first-layer/
        CompatibleRuntimes:
          - nodejs14.x
      Metadata:
        BuildMethod: nodejs14.x
  
    SecondLayer:
      Type: AWS::Serverless::LayerVersion
      Properties:
        LayerName: SecondLayer
        Description: Second layer of dependencies
        ContentUri: layers/second-layer/
        CompatibleRuntimes:
          - nodejs14.x
      Metadata:
        BuildMethod: nodejs14.x
  
    MyLambda:
      Type: AWS::Serverless::Function
      Properties:
        FunctionName: &quot;MyLambda&quot;
        Policies:
          - AmazonS3FullAccess
        CodeUri: src/
        Handler: lambda.handler
        Timeout: 30
        MemorySize: 2048 # Chrome will require higher memory
        Runtime: nodejs14.x
        Layers:
          - !Ref FirstLayer
          - !Ref SecondLayer
  </code></pre>
  <p>With this template I am able to start and invoke <code>MyLambda</code> locally and also deploy it to AWS. The problem I have is that I would like to reuse these same layers on other Lambdas as well, so for doing that I could simply extract these layers to another <code>yml</code> file, deploy them separately and then include the layers ARNs in the <code>Layers</code> property of my Lambda, but then, how can I run it locally with <code>sam</code>? I wouldn't like to have 2 <code>template.yml</code> files for my Lambda, one including the Layers on the <code>Resources</code> (like the one I already have) to run locally and another one with the refs to the actual layers ARNs to deploy on AWS, but that's the only solution I am seeing now.</p>