gpt4 book ai didi

amazon-web-services - Cloudformation循环依赖困惑

转载 作者:行者123 更新时间:2023-12-03 07:36:59 25 4
gpt4 key购买 nike

我对 Cloudformation 的循环依赖问题完全迷失了。我编写了这个模板,它可以很好地从 CLI 运行,但是当我尝试从浏览器作为堆栈启动它时,我遇到了这个循环依赖问题。

有人可以告诉我依赖性从何而来吗?

这是我得到的错误

Circular dependency between resources: [VehiclesLambda, HelloAPI, AuthorizerFuncPerm]

这是我的模板

AWSTemplateFormatVersion: '2010-09-09'
Description: Yes you can use SAM to create an Authorizer
Parameters:
Environment:
Type: String
Default: dev
Outputs:
ExampleAPIUrl:
Value: !Sub "https://${HelloAPI}.execute-api.${AWS::Region}.amazonaws.com/${Environment}/"
Resources:
HelloAPI:
Type: AWS::Serverless::Api
Properties:
StageName: !Sub ${Environment}
DefinitionBody:
swagger: 2.0
info:
title:
Ref: AWS::StackName
securityDefinitions:
test-authorizer:
type: apiKey
name: Authorization
in: header
x-amazon-apigateway-authtype: custom
x-amazon-apigateway-authorizer:
type: token
authorizerUri:
Fn::Sub: arn:aws:apigateway:${AWS::Region}:lambda:path/2015-03-31/functions/${AuthorizerFunc.Arn}/invocations
authorizerResultTtlInSeconds: 5
paths:
/vehicles:
get:
x-amazon-apigateway-integration:
httpMethod: POST
type: aws_proxy
uri:
!Sub arn:aws:apigateway:${AWS::Region}:lambda:path/2015-03-31/functions/${VehiclesLambda.Arn}/invocations
responses: {}
security:
- test-authorizer: []
VehiclesLambda:
Type: AWS::Serverless::Function
Properties:
Handler: index.handler
Runtime: nodejs4.3
CodeUri: 's3://companyrentalaws/vehicles.zip'
MemorySize: 128
Timeout: 30
Policies:
- AWSLambdaBasicExecutionRole
Events:
MyEndpoint:
Type: Api
Properties:
Path: /vehicles
Method: GET
RestApiId:
Ref: HelloAPI
AuthorizerFunc:
Type: AWS::Serverless::Function
Properties:
Handler: authorizer.authorizer
Runtime: nodejs4.3
CodeUri: 's3://companyrentalaws/authorizer.zip'
AuthorizerFuncPerm:
Type: AWS::Lambda::Permission
DependsOn:
- HelloAPI
- AuthorizerFunc
Properties:
Action: lambda:InvokeFunction
FunctionName:
Ref: AuthorizerFunc
Principal: apigateway.amazonaws.com

很抱歉发布了这么多代码,但不想遗漏任何内容。

最佳答案

VehiclesLambda 有一个属性 RestApiId,它引用 HelloAPI。

            RestApiId:
Ref: HelloAPI

HelloAPI Fn:GetAttr 的 VehiclesLambda 的 Arn

!Sub arn:aws:apigateway:${AWS::Region}:lambda:path/2015-03-31/functions/${VehiclesLambda.Arn}/invocations

这是你的循环依赖。

关于amazon-web-services - Cloudformation循环依赖困惑,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/51235089/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com