0
votes

I think i do something wrong in my .yaml file. Probably its problem with AWS::Serverless::Api. Before i add it everything was fine. I just want to configure api with authorization. I also want to know how to configure which request will be authorized. I had this error after deploy command:

Initiating deployment

Waiting for changeset to be created.. Error: Failed to create changeset for the stack: SampleImagesApi, ex: Waiter ChangeSetCreateComplete failed: Waiter encountered a terminal failure state Status: FAILED. Reason: Unresolved resource dependencies [ServerlessRestApi] in the Outputs block of the template

AWSTemplateFormatVersion: '2010-09-09'
Transform: AWS::Serverless-2016-10-31
Description: >
  python3.8

  Sample SAM Template for SampleAwsImagesApi

# More info about Globals: https://github.com/awslabs/serverless-application-model/blob/master/docs/globals.rst
Globals:
  Function:
    Timeout: 3

Resources:
  MyApi:
    Type: AWS::Serverless::Api
    DependsOn:
    Properties:
      StageName: prod
      Auth:
        DefaultAuthorizer: MyLambdaTokenAuth
        Authorizers:
          MyLambdaTokenAuth:
            FunctionPayloadType: REQUEST
            FunctionArn: !GetAtt AuthFunction.Arn
            Identity:
              Headers: Authorization # OPTIONAL; Default: 'Authorization'
              ValidationExpression: Bearer *
              ReauthorizeEvery: 20 # OPTIONAL; Service Default: 300
  HelloWorldFunction:
    Type: AWS::Serverless::Function # More info about Function Resource: https://github.com/awslabs/serverless-application-model/blob/master/versions/2016-10-31.md#awsserverlessfunction
    Properties:
      PackageType: Image
      Events:
        HelloWorld:
          Type: Api # More info about API Event Source: https://github.com/awslabs/serverless-application-model/blob/master/versions/2016-10-31.md#api
          Properties:
            Path: /hello
            Method: get
            RestApiId:
              Ref: MyApi
    Metadata:
      Dockerfile: Dockerfile
      DockerContext: ./hello_world
      DockerTag: python3.8-v1
  HelloWorld2Function:
    Type: AWS::Serverless::Function # More info about Function Resource: https://github.com/awslabs/serverless-application-model/blob/master/versions/2016-10-31.md#awsserverlessfunction
    Properties:
      PackageType: Image
      Events:
        HelloWorld:
          Type: Api # More info about API Event Source: https://github.com/awslabs/serverless-application-model/blob/master/versions/2016-10-31.md#api
          Properties:
            Path: /hello2
            Method: get
            RestApiId:
              Ref: MyApi
    Metadata:
      Dockerfile: Dockerfile
      DockerContext: ./hello_world2
      DockerTag: python3.8-v1
  LoginFunction:
    Type: AWS::Serverless::Function # More info about Function Resource: https://github.com/awslabs/serverless-application-model/blob/master/versions/2016-10-31.md#awsserverlessfunction
    Properties:
      PackageType: Image
      Events:
        HelloWorld:
          Type: Api # More info about API Event Source: https://github.com/awslabs/serverless-application-model/blob/master/versions/2016-10-31.md#api
          Properties:
            Path: /login
            Method: post
            RestApiId:
              Ref: MyApi
    Metadata:
      Dockerfile: Dockerfile
      DockerContext: ./login
      DockerTag: python3.8-v1
  AuthFunction:
    Type: AWS::Serverless::Function # More info about Function Resource: https://github.com/awslabs/serverless-application-model/blob/master/versions/2016-10-31.md#awsserverlessfunction
    Properties:
      PackageType: Image
    Metadata:
      Dockerfile: Dockerfile
      DockerContext: ./auth
      DockerTag: python3.8-v1

Outputs:
  # ServerlessRestApi is an implicit API created out of Events key under Serverless::Function
  # Find out more about other implicit resources you can reference within SAM
  # https://github.com/awslabs/serverless-application-model/blob/master/docs/internals/generated_resources.rst#api
  HelloWorldApi:
    Description: "API Gateway endpoint URL for Prod stage for Hello World function"
    Value: !Sub "https://${ServerlessRestApi}.execute-api.${AWS::Region}.amazonaws.com/Prod/hello/"
  HelloWorldFunction:
    Description: "Hello World Lambda Function ARN"
    Value: !GetAtt HelloWorldFunction.Arn
  HelloWorldFunctionIamRole:
    Description: "Implicit IAM Role created for Hello World function"
    Value: !GetAtt HelloWorldFunctionRole.Arn
1

1 Answers

0
votes

using cfn-lint CLI to validate your template can help you debug it - https://github.com/aws-cloudformation/cfn-python-lint

I tried it locally and there's a couple of errors going on:

E0000 Null value at line 16 column 15
template-2.yaml:16:15

E0001 Error transforming template: Resource with id [AuthFunction] is invalid. 'ImageUri' must be set.
template.yaml:1:1

E0001 Error transforming template: Resource with id [HelloWorld2Function] is invalid. 'ImageUri' must be set.
template.yaml:1:1

E0001 Error transforming template: Resource with id [HelloWorldFunction] is invalid. 'ImageUri' must be set.
template.yaml:1:1

E0001 Error transforming template: Resource with id [LoginFunction] is invalid. 'ImageUri' must be set.
template.yaml:1:1