title: AWS SAM local API debugging : How to test the access with an API key?
body: <p>I am currently learning AWS Serverless Application Model (SAM).</p>
  <p>With that objective, I created a simple template that is deploying a Python Lambda function and an API which calls this function. My template is the following :</p>
  <pre class="lang-yaml prettyprint-override"><code>AWSTemplateFormatVersion: '2010-09-09'
  Transform: AWS::Serverless-2016-10-31
  Description: &gt;
    a test with AWS SAM
  
  Globals:
    Function:
      Timeout: 10
    Api:
      OpenApiVersion: 3.0.1
  
  Resources:
    HelloAPI:
      Type: AWS::Serverless::Api
      Properties:
        StageName: dev
        Auth:
          ApiKeyRequired: true
          UsagePlan:
            CreateUsagePlan: PER_API
            Description: Usage plan for this API
    HelloFunction:
      Properties:
        CodeUri: some/path/to/hello_function
        Handler: hello.lambda_handler
        Runtime: python3.8
        Events:
          Hello:
            Type: Api 
            Properties:
              RestApiId: !Ref HelloAPI
              Path: /
              Method: post        
  
  Outputs:
    ProdDataEndpoint:
      Description: &quot;API dev stage endpoint&quot;
      Value: !Sub &quot;https://${HelloAPI}.execute-api.${AWS::Region}.amazonaws.com/dev/&quot;
  </code></pre>
  <p>So the template creates a UsagePlan with an associated API key. I checked within AWS, the ressources are indeed created correcly.</p>
  <p>I can test the API locally with :</p>
  <pre class="lang-sh prettyprint-override"><code>sam local start-api
  sam local generate-event apigateway aws-proxy &gt; local-event.json
  curl -d &quot;@local-event.json&quot; -X POST http://127.0.0.1:3000/
  </code></pre>
  <p>And this works. But I don't know how to test it with the API key to check if the access is indeed protected by the key. Does anyone know how to do that?</p>
  <p>Thanks !</p>