Automate API Gateway deployment via SAM deploy?

I’m trying to reflect the changes I made to AWS::ApiGateway::Method properties in my AWS SAM template when I deploy the application. However, when I deploy the application, the changes are not reflected until I manually deploy the API on the AWS management console.

It appears that this is because I have not changed the AWS::ApiGateway::Deployment and AWS::ApiGateway::Stage resources on the template, and the deployment history of AWS::ApiGateway::Stage is not being updated.

How can I ensure that the changes I make are reflected when I trigger a SAM deploy?

You can add a DependsOn attribute to your AWS::ApiGateway::Deployment and AWS::ApiGateway::Stage resources, specifying the AWS::ApiGateway::Method resources that you want to update. This will ensure that the deployment and stage resources are updated whenever there are changes to the method resources.

Example:

Resources:
  MyApi:
    Type: AWS::Serverless::Api
    Properties:
      StageName: prod
      DefinitionBody:
        swagger: "2.0"
        info:
          title: "My API"
        paths:
          /myendpoint:
            get:
              x-amazon-apigateway-integration:
                uri: "arn:aws:apigateway:us-east-1:lambda:path/2015-03-31/functions/arn:aws:lambda:us-east-1:123456789012:function:myfunction/invocations"
                httpMethod: "POST"
                type: "aws_proxy"
              responses: {}
              security: []
  MyDeployment:
    Type: AWS::ApiGateway::Deployment
    DependsOn:
      - MyMethod
  MyStage:
    Type: AWS::ApiGateway::Stage
    Properties:
      DeploymentId: !Ref MyDeployment
      RestApiId: !Ref MyApi
      StageName: prod
    DependsOn:
      - MyDeployment
  MyMethod:
    Type: AWS::ApiGateway::Method
    Properties:
      RestApiId: !Ref MyApi
      ResourceId: !GetAtt MyApi.RootResourceId
      HttpMethod: GET
      AuthorizationType: NONE
      Integration:
        Type: AWS_PROXY
        IntegrationHttpMethod: POST
        Uri: !Sub arn:aws:apigateway:${AWS::Region}:lambda:path/2015-03-31/functions/${MyFunction.Arn}/invocations