我想我在。yaml文件中做错了什么。可能是AWS::Serverless::Api的问题.在我添加之前,一切都很好。我只是想配置api授权。我还想知道如何配置哪些请求将被授权。我在部署命令后出现了这个错误:
初始部署
等待创建变更集。错误:Failed to create changesset for stack: SampleImagesApi, ex: Waiter ChangeSetCreateComplete Failed: Waiter遇到终端失败状态Status: Failed。原因:未解决的资源依赖[ServerlessRestApi]在模板的输出块
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
使用cfn-lint
CLI来验证你的模板可以帮助你调试它- https://github.com/aws-cloudformation/cfn-python-lint
我在本地尝试了一下,有几个错误正在发生:
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