AWS SAM - How to override generated resources

0

I'm trying to build a REST API with SAM. My YAML file looks like this:

AWSTemplateFormatVersion: "2010-09-09"
Description: >-
  example-rest-api

Transform:
- AWS::Serverless-2016-10-31

Resources:
  allEquipmentsFunction:
    Type: AWS::Serverless::Function
    Properties:
      Handler: src/handlers/myModel.getAll
      Runtime: nodejs18.x
      Architectures:
      - x86_64
      MemorySize: 128
      Timeout: 100
      Description: example description
      Events:
        ApiEvent:
          Type: Api
          Properties:
            Path: /
            Method: GET

  saveEquipmentFunction:
    Type: AWS::Serverless::Function
    Properties:
      Handler: src/handlers/myModel.save
      Runtime: nodejs18.x
      Architectures:
      - x86_64
      MemorySize: 128
      Timeout: 100
      Description: example description
      Events:
        Api:
          Type: Api
          Properties:
            Path: /
            Method: POST

  ApplicationResourceGroup:
    Type: AWS::ResourceGroups::Group
    Properties:
      Name:
        Fn::Join:
        - ''
        - - ApplicationInsights-SAM-
          - Ref: AWS::StackName
      ResourceQuery:
        Type: CLOUDFORMATION_STACK_1_0
  ApplicationInsightsMonitoring:
    Type: AWS::ApplicationInsights::Application
    Properties:
      ResourceGroupName:
        Fn::Join:
        - ''
        - - ApplicationInsights-SAM-
          - Ref: AWS::StackName
      AutoConfigurationEnabled: 'true'
    DependsOn: ApplicationResourceGroup
Outputs:
  WebEndpoint:
    Description: API Gateway endpoint URL for Prod stage
    Value: !Sub "https://${ServerlessRestApi}.execute-api.${AWS::Region}.amazonaws.com/{Stage}"

As I understand it, SAM creates some resources for me in the background. For example:

"ServerlessRestApi": {
      "Type": "AWS::ApiGateway::RestApi"
      ...

How can I override these generated resources? I want to add API Gateway validation model. For this I need to override background generated resources. AWS Resources is not clean enough. What approach should I take if I can't override?

1 Answer
1

The AWS::Serverless::API will get created for you if you dont' define it but I think you'll need to for request validation. https://docs.aws.amazon.com/serverless-application-model/latest/developerguide/sam-resource-api.html

To set up request validation:

AWS
Clay_B
answered a year ago

You are not logged in. Log in to post an answer.

A good answer clearly answers the question and provides constructive feedback and encourages professional growth in the question asker.

Guidelines for Answering Questions