我想我的.yaml文件做错了什么。可能是AWS::Serverless::Api.的问题在我加进去之前一切都很好。我只想用授权来配置api。我还想知道如何配置哪些请求将被授权。部署命令后出现了此错误:
启动部署
等待变更集被创建。错误:未能为堆栈创建更改集: SampleImagesApi,例如: ChangeSetCreateComplete失败:服务生遇到终端故障状态:失败。原因:模板的输出块中未解析的资源依赖项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发布于 2021-03-18 09:07:07
使用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:1https://stackoverflow.com/questions/66535459
复制相似问题