API hitting for sam template resources gets internal server error

13 Views Asked by At

I have been hitting out the API, the api's for console approach working fine.

However, the sam template resources api's are not working says internal server error.

Logs are not being generated on CloudWatch, made sure to include all the permissions.

Does anyone faced similar issue? Please help.

My sam template is:

AWSTemplateFormatVersion: '2010-09-09'
Transform: 'AWS::Serverless-2016-10-31'
Description: "SAM Template for Rekognition-related functions and API Gateway"

Globals:
  Function:
    Timeout: 10
    MemorySize: 256

Resources:
  StartModelFunction:
    Type: 'AWS::Serverless::Function'
    Properties:
      Handler: lambda_function.lambda_handler
      Runtime: python3.9
      FunctionName: start-model-rekog
      Description: Lambda function to start a model in Rekognition
      CodeUri: start-model-rekog/
      Events:
        StartModelApiEvent:
          Type: Api
          Properties:
            Path: /start-model-rekog
            Method: get
            
  ApiGatewayApi:
    Type: 'AWS::Serverless::Api'
    Properties:
      StageName: v1
      DefinitionBody:
        swagger: '2.0'
        info:
          title: 'startmodelrekog'
          version: '1.0'
        paths:
          /start-modelnew:
            get:
              responses:
                '200':
                  description: 'Successful response'
              x-amazon-apigateway-integration:
                uri:
                  Fn::Sub: arn:aws:apigateway:${AWS::Region}:lambda:path/2015-03-31/functions/${StartModelFunction.Arn}/invocations
                passthroughBehavior: when_no_match
                httpMethod: GET
                type: aws

  UploadDataFunction:
    Type: 'AWS::Serverless::Function'
    Properties:
      Handler: lambda_function.lambda_handler
      Runtime: python3.9
      FunctionName: upload-data-rekog
      Description: Lambda function for uploading data
      CodeUri: upload-data-rekog/
      Events:
        UploadDataApiEvent:
          Type: Api
          Properties:
            Path: /upload-data-rekog/{bucket}
            Method: get

  UploadDataApi:
    Type: 'AWS::Serverless::Api'
    Properties:
      StageName: v1
      DefinitionBody:
        swagger: '2.0'
        info:
          title: 'uploaddatarekog'
          version: '1.0'
        paths:
          /{bucket}:
            get:
              responses:
                '200':
                  description: 'Successful response'
              x-amazon-apigateway-integration:
                uri:
                  Fn::Sub: arn:aws:apigateway:${AWS::Region}:lambda:path/2015-03-31/functions/${UploadDataFunction.Arn}/invocations
                passthroughBehavior: when_no_match
                httpMethod: GET
                type: aws_proxy

  MyS3Bucket:
    Type: 'AWS::S3::Bucket'
    Properties:
      BucketName: testbucketsam-rekog

  ClassifyLambdaFunction:
    Type: 'AWS::Serverless::Function'
    Properties:
      Handler: lambda_function.lambda_handler
      Runtime: python3.9
      FunctionName: classifyimage-rekog
      Description: Lambda function for classification
      CodeUri: classifyimage-rekog/
      Events:
        S3Event:
          Type: S3
          Properties:
            Bucket: !Ref MyS3Bucket
            Events: s3:ObjectCreated:*

  StartModelFunctionApiGatewayPermission:
    Type: 'AWS::Lambda::Permission'
    Properties:
      Action: 'lambda:InvokeFunction'
      FunctionName: !GetAtt StartModelFunction.Arn
      Principal: 'apigateway.amazonaws.com'
      SourceArn: !Sub "arn:aws:execute-api:${AWS::Region}:${AWS::AccountId}:${ApiGatewayApi}/*/*/*"

  UploadDataFunctionApiGatewayPermission:
    Type: 'AWS::Lambda::Permission'
    Properties:
      Action: 'lambda:InvokeFunction'
      FunctionName: !GetAtt UploadDataFunction.Arn
      Principal: 'apigateway.amazonaws.com'
      SourceArn: !Sub "arn:aws:execute-api:${AWS::Region}:${AWS::AccountId}:${ApiGatewayApi}/*/*/*"

Outputs:
  StartModelFunctionArn:
    Value: !GetAtt StartModelFunction.Arn
  UploadDataFunctionArn:
    Value: !GetAtt UploadDataFunction.Arn
  ClassifyLambdaFunctionArn:
    Value: !GetAtt ClassifyLambdaFunction.Arn
0

There are 0 best solutions below