AWS SAM Template - Local Testing












1















I have a AWS SAM template that I'm trying to test locally and then deploy. The local test runs (sam local start-api) but the payload is not validated. This means that I have a RequestValidator in place, but it does not validate a thing.



Then, I try to deploy the YAML file to AWS to test there, and I get an error that reads:




"Failed to create the changeset: Waiter ChangeSetCreateComplete
failed: Waiter encountered a terminal failure state Status: FAILED.
Reason: Transform AWS::Serverless-2016-10-31 failed with: Invalid
Serverless Application Specification document. Number of errors found:
1. Resource with id [BoilerPlateFunction] is invalid. Event with id [ApiEvent] is invalid. RestApiId property of Api event must reference
a valid resource in the same template."




This is my yaml file, so first I want to be able to make the RequestValidator work in my local and once that is done, to know what I'm doing wrong and why I can't deploy:



AWSTemplateFormatVersion: '2010-09-09'
Transform: AWS::Serverless-2016-10-31
Description: >
sam-app

Sample SAM Template for sam-app

Globals:
Function:
Timeout: 20
Parameters:
operationName:
Type: String
Default: testoperationName
restApiName:
Type: String
Default: testrestApiName
validatorName:
Type: String
Default: testvalidatorName
validateRequestBody:
Type: String
Default: testvalidateRequestBody
validateRequestParameters:
Type: String
Default: true
Resources:
BoilerPlateApi:
Type: AWS::ApiGateway::Api
Properties:
Name: !Ref restApiName
BoilerPlateFunctionMethod:
Type: AWS::ApiGateway::Method
Properties:
HttpMethod: ANY
RestApiId: !Ref BoilerPlateApi
RequestValidatorId: !Ref RequestValidator
RequestParameters:
method.request.querystring.test: true
RequestValidator:
Type: AWS::ApiGateway::RequestValidator
Properties:
Name: !Ref validatorName
RestApiId: !Ref BoilerPlateApi
ValidateRequestParameters: !Ref validateRequestParameters
BoilerPlateFunction:
Type: AWS::Serverless::Function
Properties:
CodeUri: boilerplate/apiName
Handler: index.handler
Runtime: nodejs8.10
Events:
ApiEvent:
Type: Api
Properties:
RestApiId: !Ref BoilerPlateApi
Path: /hello
Method: GET


So again, that runs using sam local start-api, I can hit the endpoint and the Lambda is executed. But I expect the API gateway to throw an error if I don't include the "test" parameter in the query string, but it does not, it let it go through.



Thanks guys!










share|improve this question



























    1















    I have a AWS SAM template that I'm trying to test locally and then deploy. The local test runs (sam local start-api) but the payload is not validated. This means that I have a RequestValidator in place, but it does not validate a thing.



    Then, I try to deploy the YAML file to AWS to test there, and I get an error that reads:




    "Failed to create the changeset: Waiter ChangeSetCreateComplete
    failed: Waiter encountered a terminal failure state Status: FAILED.
    Reason: Transform AWS::Serverless-2016-10-31 failed with: Invalid
    Serverless Application Specification document. Number of errors found:
    1. Resource with id [BoilerPlateFunction] is invalid. Event with id [ApiEvent] is invalid. RestApiId property of Api event must reference
    a valid resource in the same template."




    This is my yaml file, so first I want to be able to make the RequestValidator work in my local and once that is done, to know what I'm doing wrong and why I can't deploy:



    AWSTemplateFormatVersion: '2010-09-09'
    Transform: AWS::Serverless-2016-10-31
    Description: >
    sam-app

    Sample SAM Template for sam-app

    Globals:
    Function:
    Timeout: 20
    Parameters:
    operationName:
    Type: String
    Default: testoperationName
    restApiName:
    Type: String
    Default: testrestApiName
    validatorName:
    Type: String
    Default: testvalidatorName
    validateRequestBody:
    Type: String
    Default: testvalidateRequestBody
    validateRequestParameters:
    Type: String
    Default: true
    Resources:
    BoilerPlateApi:
    Type: AWS::ApiGateway::Api
    Properties:
    Name: !Ref restApiName
    BoilerPlateFunctionMethod:
    Type: AWS::ApiGateway::Method
    Properties:
    HttpMethod: ANY
    RestApiId: !Ref BoilerPlateApi
    RequestValidatorId: !Ref RequestValidator
    RequestParameters:
    method.request.querystring.test: true
    RequestValidator:
    Type: AWS::ApiGateway::RequestValidator
    Properties:
    Name: !Ref validatorName
    RestApiId: !Ref BoilerPlateApi
    ValidateRequestParameters: !Ref validateRequestParameters
    BoilerPlateFunction:
    Type: AWS::Serverless::Function
    Properties:
    CodeUri: boilerplate/apiName
    Handler: index.handler
    Runtime: nodejs8.10
    Events:
    ApiEvent:
    Type: Api
    Properties:
    RestApiId: !Ref BoilerPlateApi
    Path: /hello
    Method: GET


    So again, that runs using sam local start-api, I can hit the endpoint and the Lambda is executed. But I expect the API gateway to throw an error if I don't include the "test" parameter in the query string, but it does not, it let it go through.



    Thanks guys!










    share|improve this question

























      1












      1








      1








      I have a AWS SAM template that I'm trying to test locally and then deploy. The local test runs (sam local start-api) but the payload is not validated. This means that I have a RequestValidator in place, but it does not validate a thing.



      Then, I try to deploy the YAML file to AWS to test there, and I get an error that reads:




      "Failed to create the changeset: Waiter ChangeSetCreateComplete
      failed: Waiter encountered a terminal failure state Status: FAILED.
      Reason: Transform AWS::Serverless-2016-10-31 failed with: Invalid
      Serverless Application Specification document. Number of errors found:
      1. Resource with id [BoilerPlateFunction] is invalid. Event with id [ApiEvent] is invalid. RestApiId property of Api event must reference
      a valid resource in the same template."




      This is my yaml file, so first I want to be able to make the RequestValidator work in my local and once that is done, to know what I'm doing wrong and why I can't deploy:



      AWSTemplateFormatVersion: '2010-09-09'
      Transform: AWS::Serverless-2016-10-31
      Description: >
      sam-app

      Sample SAM Template for sam-app

      Globals:
      Function:
      Timeout: 20
      Parameters:
      operationName:
      Type: String
      Default: testoperationName
      restApiName:
      Type: String
      Default: testrestApiName
      validatorName:
      Type: String
      Default: testvalidatorName
      validateRequestBody:
      Type: String
      Default: testvalidateRequestBody
      validateRequestParameters:
      Type: String
      Default: true
      Resources:
      BoilerPlateApi:
      Type: AWS::ApiGateway::Api
      Properties:
      Name: !Ref restApiName
      BoilerPlateFunctionMethod:
      Type: AWS::ApiGateway::Method
      Properties:
      HttpMethod: ANY
      RestApiId: !Ref BoilerPlateApi
      RequestValidatorId: !Ref RequestValidator
      RequestParameters:
      method.request.querystring.test: true
      RequestValidator:
      Type: AWS::ApiGateway::RequestValidator
      Properties:
      Name: !Ref validatorName
      RestApiId: !Ref BoilerPlateApi
      ValidateRequestParameters: !Ref validateRequestParameters
      BoilerPlateFunction:
      Type: AWS::Serverless::Function
      Properties:
      CodeUri: boilerplate/apiName
      Handler: index.handler
      Runtime: nodejs8.10
      Events:
      ApiEvent:
      Type: Api
      Properties:
      RestApiId: !Ref BoilerPlateApi
      Path: /hello
      Method: GET


      So again, that runs using sam local start-api, I can hit the endpoint and the Lambda is executed. But I expect the API gateway to throw an error if I don't include the "test" parameter in the query string, but it does not, it let it go through.



      Thanks guys!










      share|improve this question














      I have a AWS SAM template that I'm trying to test locally and then deploy. The local test runs (sam local start-api) but the payload is not validated. This means that I have a RequestValidator in place, but it does not validate a thing.



      Then, I try to deploy the YAML file to AWS to test there, and I get an error that reads:




      "Failed to create the changeset: Waiter ChangeSetCreateComplete
      failed: Waiter encountered a terminal failure state Status: FAILED.
      Reason: Transform AWS::Serverless-2016-10-31 failed with: Invalid
      Serverless Application Specification document. Number of errors found:
      1. Resource with id [BoilerPlateFunction] is invalid. Event with id [ApiEvent] is invalid. RestApiId property of Api event must reference
      a valid resource in the same template."




      This is my yaml file, so first I want to be able to make the RequestValidator work in my local and once that is done, to know what I'm doing wrong and why I can't deploy:



      AWSTemplateFormatVersion: '2010-09-09'
      Transform: AWS::Serverless-2016-10-31
      Description: >
      sam-app

      Sample SAM Template for sam-app

      Globals:
      Function:
      Timeout: 20
      Parameters:
      operationName:
      Type: String
      Default: testoperationName
      restApiName:
      Type: String
      Default: testrestApiName
      validatorName:
      Type: String
      Default: testvalidatorName
      validateRequestBody:
      Type: String
      Default: testvalidateRequestBody
      validateRequestParameters:
      Type: String
      Default: true
      Resources:
      BoilerPlateApi:
      Type: AWS::ApiGateway::Api
      Properties:
      Name: !Ref restApiName
      BoilerPlateFunctionMethod:
      Type: AWS::ApiGateway::Method
      Properties:
      HttpMethod: ANY
      RestApiId: !Ref BoilerPlateApi
      RequestValidatorId: !Ref RequestValidator
      RequestParameters:
      method.request.querystring.test: true
      RequestValidator:
      Type: AWS::ApiGateway::RequestValidator
      Properties:
      Name: !Ref validatorName
      RestApiId: !Ref BoilerPlateApi
      ValidateRequestParameters: !Ref validateRequestParameters
      BoilerPlateFunction:
      Type: AWS::Serverless::Function
      Properties:
      CodeUri: boilerplate/apiName
      Handler: index.handler
      Runtime: nodejs8.10
      Events:
      ApiEvent:
      Type: Api
      Properties:
      RestApiId: !Ref BoilerPlateApi
      Path: /hello
      Method: GET


      So again, that runs using sam local start-api, I can hit the endpoint and the Lambda is executed. But I expect the API gateway to throw an error if I don't include the "test" parameter in the query string, but it does not, it let it go through.



      Thanks guys!







      amazon-web-services aws-serverless






      share|improve this question













      share|improve this question











      share|improve this question




      share|improve this question










      asked Nov 21 '18 at 23:35









      LaerionLaerion

      170315




      170315
























          0






          active

          oldest

          votes











          Your Answer






          StackExchange.ifUsing("editor", function () {
          StackExchange.using("externalEditor", function () {
          StackExchange.using("snippets", function () {
          StackExchange.snippets.init();
          });
          });
          }, "code-snippets");

          StackExchange.ready(function() {
          var channelOptions = {
          tags: "".split(" "),
          id: "1"
          };
          initTagRenderer("".split(" "), "".split(" "), channelOptions);

          StackExchange.using("externalEditor", function() {
          // Have to fire editor after snippets, if snippets enabled
          if (StackExchange.settings.snippets.snippetsEnabled) {
          StackExchange.using("snippets", function() {
          createEditor();
          });
          }
          else {
          createEditor();
          }
          });

          function createEditor() {
          StackExchange.prepareEditor({
          heartbeatType: 'answer',
          autoActivateHeartbeat: false,
          convertImagesToLinks: true,
          noModals: true,
          showLowRepImageUploadWarning: true,
          reputationToPostImages: 10,
          bindNavPrevention: true,
          postfix: "",
          imageUploader: {
          brandingHtml: "Powered by u003ca class="icon-imgur-white" href="https://imgur.com/"u003eu003c/au003e",
          contentPolicyHtml: "User contributions licensed under u003ca href="https://creativecommons.org/licenses/by-sa/3.0/"u003ecc by-sa 3.0 with attribution requiredu003c/au003e u003ca href="https://stackoverflow.com/legal/content-policy"u003e(content policy)u003c/au003e",
          allowUrls: true
          },
          onDemand: true,
          discardSelector: ".discard-answer"
          ,immediatelyShowMarkdownHelp:true
          });


          }
          });














          draft saved

          draft discarded


















          StackExchange.ready(
          function () {
          StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f53421936%2faws-sam-template-local-testing%23new-answer', 'question_page');
          }
          );

          Post as a guest















          Required, but never shown

























          0






          active

          oldest

          votes








          0






          active

          oldest

          votes









          active

          oldest

          votes






          active

          oldest

          votes
















          draft saved

          draft discarded




















































          Thanks for contributing an answer to Stack Overflow!


          • Please be sure to answer the question. Provide details and share your research!

          But avoid



          • Asking for help, clarification, or responding to other answers.

          • Making statements based on opinion; back them up with references or personal experience.


          To learn more, see our tips on writing great answers.




          draft saved


          draft discarded














          StackExchange.ready(
          function () {
          StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f53421936%2faws-sam-template-local-testing%23new-answer', 'question_page');
          }
          );

          Post as a guest















          Required, but never shown





















































          Required, but never shown














          Required, but never shown












          Required, but never shown







          Required, but never shown

































          Required, but never shown














          Required, but never shown












          Required, but never shown







          Required, but never shown







          Popular posts from this blog

          "Incorrect syntax near the keyword 'ON'. (on update cascade, on delete cascade,)

          Alcedinidae

          Origin of the phrase “under your belt”?