为ApiGatewayV2 Target属性添加"DependsOn"语句,以保证其所依赖的资源已经被创建。
以下是一个示例CloudFormation模板,其中ApiGatewayV2 Target属性被设置为依赖于API Gateway的HTTP API资源:
Resources:
MyHttpApi:
Type: AWS::ApiGatewayV2::Api
Properties:
Name: my-http-api
MyLambdaFunction:
Type: AWS::Lambda::Function
Properties:
Code: ...
Handler: ...
Role: ...
MyIntegration:
Type: AWS::ApiGatewayV2::Integration
Properties:
ApiId: !Ref MyHttpApi
IntegrationType: AWS_PROXY
IntegrationUri: !Sub "arn:aws:lambda:${AWS::Region}:${AWS::AccountId}:function:${MyLambdaFunction}"
MyRoute:
Type: AWS::ApiGatewayV2::Route
Properties:
ApiId: !Ref MyHttpApi
RouteKey: "GET /"
Target: !Sub "integrations/${MyIntegration}"
DependsOn:
- MyIntegration
MyTarget:
Type: AWS::ApiGatewayV2::ApiGatewayManagedOverrides
Properties:
ApiId: !Ref MyHttpApi
Integration: !Ref MyIntegration
TargetManagedOverrides:
Target: !Sub "arn:${AWS::Partition}:apigateway:${AWS::Region}:${AWS::AccountId}:/api/v2/httpapis/${MyHttpApi}/targets/${MyIntegration}"
DependsOn:
- MyIntegration