gpt4 book ai didi

aws-lambda - 模板包含错误。: 模板错误:Fn::GetAtt 实例引用 api 网关中未定义的资源 LambdaInvokeFunction

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

我遇到了同样的错误。这是我的全部代码。任何人都可以解决它吗?

    
AWSTemplateFormatVersion: 2010-09-09
Description: My API Gateway and Lambda function

Parameters:
ResourcesPrefix:
Type: String
Default: Nds-Cync
EnvironmentType:
Type: String
Default: Prod
ServiceName:
Type: String
Default: UserTourGuideApp
RestApi:
Type: String
Default: ''
StageName:
Type: String
Default: v1
lambdaFunctionName:
Type: String
Default: proxy-lambda

Resources:
LambdaFunction:
Type: AWS::Lambda::Function
Properties:
Description: AWS Lambda function
FunctionName: !Ref lambdaFunctionName
Handler: index.handler
MemorySize: 256
Role: !GetAtt LambdaIamRole.Arn
Runtime: python3.7
Timeout: 60
apiGateway:
Type: AWS::ApiGateway::RestApi
Properties:
Name: !Sub '${ResourcesPrefix}-${EnvironmentType}-${ServiceName}'
Description: Example API Gateway
EndpointConfiguration:
Types:
- REGIONAL
LambdaResource:
Type: 'AWS::ApiGateway::Resource'
Properties:
ApiId: !Ref apiGateway
ParentId: !GetAtt apiGateway.RootResourceId
Path_Part: 'lambdaFunctionName'

ANY:
Type: 'AWS::ApiGateway::Method'
Properties:
AuthorizationType: NONE
ApiKeyRequired: false
RestApiId: !Ref apiGateway
ResourceId: !Ref LambdaResource
HttpMethod: ANY
Integration:
Type: LAMBDA_PROXY
IntegrationHttpMethod: POST
Uri: !Sub
- >-
arn:aws:apigateway:${AWS::Region}:lambda:path/2015-03-31/functions/${lambdaArn}/invocations
- lambdaArn: !GetAtt lambdaFunction.Arn
MethodResponses:
- StatusCode: 200
ResponseModels: { "application/json": "Empty" }

Options:
Type: "AWS::ApiGateway::Method"
Properties:
ResourceId: !Ref LambdaResource
RestApiId: !Ref apiGateway
AuthorizationType: NONE
HttpMethod: OPTIONS
Integration:
Type: MOCK
IntegrationResponses:
- ResponseParameters:
method.response.header.Access-Control-Allow-Headers: "'Content-Type,X-Amz-Date,Authorization,X-Api-Key,X-Amz-Security-Token'"
method.response.header.Access-Control-Allow-Methods: "'POST,OPTIONS'"
method.response.header.Access-Control-Allow-Origin: "'*'"
StatusCode: '200'
PassthroughBehavior: WHEN_NO_MATCH
MethodResponses:
- ResponseModels:
application/json: Empty
ResponseParameters:
method.response.header.Access-Control-Allow-Headers: true
method.response.header.Access-Control-Allow-Methods: true
method.response.header.Access-Control-Allow-Origin: true
StatusCode: '200'

Any:
Type: 'AWS::ApiGateway::Method'
Properties:
AuthorizationType: NONE
RestApiId: !Ref apiGateway
ResourceId: !Ref LambdaResource
HttpMethod: ANY
Integration:
Type: LAMBDA_PROXY
IntegrationHttpMethod: POST
Uri: !Sub
- >-
arn:aws:apigateway:${AWS::Region}:lambda:path/2015-03-31/functions/${lambdaArn}/invocations
- lambdaArn: !GetAtt lambdaFunction.Arn
MethodResponses:
- StatusCode: 200
ResponseModels: { "application/json": "Empty" }
Options:
Type: "AWS::ApiGateway::Method"
Properties:
ResourceId: !Ref LambdaResource
RestApiId: !Ref apiGateway
AuthorizationType: NONE
HttpMethod: OPTIONS
Integration:
Type: MOCK
IntegrationResponses:
- ResponseParameters:
method.response.header.Access-Control-Allow-Headers: "'Content-Type,X-Amz-Date,Authorization,X-Api-Key,X-Amz-Security-Token'"
method.response.header.Access-Control-Allow-Methods: "'POST,OPTIONS'"
method.response.header.Access-Control-Allow-Origin: "'*'"
ResponseTemplates:
application/json: ''
StatusCode: '200'
PassthroughBehavior: WHEN_NO_MATCH
RequestTemplates:
application/json: '{"statusCode": 200}'
MethodResponses:
- ResponseModels:
application/json: Empty
ResponseParameters:
method.response.header.Access-Control-Allow-Headers: true
method.response.header.Access-Control-Allow-Methods: true
method.response.header.Access-Control-Allow-Origin: true
StatusCode: '200'

apiDeployment:
Type: AWS::ApiGateway::Deployment
DependsOn:
- LambdaResource
Properties:
RestApiId: !Ref apiGateway
Stagename: !Ref StageName

APIGatewayPermission:
Type: 'AWS::Lambda::Permission'
Properties:
Action: 'lambda:InvokeFunction'
FunctionName:
Fn::GetAtt:
- lambdaFunctionName
- Arn
Principal: apigateway.amazonaws.com
DependsOn:
- apiDeployment

lambdaIAMRole:
Type: AWS::IAM::Role
Properties:
AssumeRolePolicyDocument:
Version: '2012-10-17'
Statement:
- Effect: 'Allow'
Principal:
Service:
- 'lambda.amazonaws.com'
Action:
- 'sts:AssumeRole'
Path: '/'
Policies:
- PolicyDocument:
Version: 2012-10-17
Statement:
- Action:
- logs:CreateLogGroup
- logs:CreateLogStream
- logs:PutLogEvents
Effect: Allow
Resource:
- !Sub arn:aws:logs:${AWS::Region}:${AWS::AccountId}:log-group:/aws/lambda/${lambdaFunctionName}:*
PolicyName: lambda
Policies:
- PolicyDocument:
Version: '2012-10-17'
Statement:
- Effect: 'Allow'
Action: 'lambda:*'
Resource: !GetAtt LambdaFunction.Arn
Policies:
- PolicyDocument:
Version: 2012-10-17
Statement:
- Effect: Allow
Action: 'lambda:InvokeFunction'
Resource: !GetAtt LambdaInvokeFunction.Arn

lambdaLogGroup:
Type: AWS::Logs::LogGroup
Properties:
LogGroupName: !Sub /aws/lambda/${lambdaFunctionName}
RetentionInDays: 90


最佳答案

您的模板未定义任何LambdaInvokeFunction。也许应该是LambdaFunction

关于aws-lambda - 模板包含错误。: 模板错误:Fn::GetAtt 实例引用 api 网关中未定义的资源 LambdaInvokeFunction,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/70639245/

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