我正在使用cloudformation制作API-GATEWAY。我面临的问题是,我想集成lambda函数在后台调用。 我已经制作了Lambda函数,并希望将其集成到我的apigateway中 有什么方法可以从CF堆栈外部导入资源?
我试图设置参数或键入lambda并以集成类型调用resourceid。
AWSTemplateFormatVersion: "2010-09-09"
Description: >
For creating Restul api gateway,
Background invocation in lambda
Parameters:
apiName:
Type: String
Default: ApolloDevB
Resources:
MyRestApi:
Type: AWS::ApiGateway::RestApi
Properties:
Name: !Ref apiName
Restapiresource:
Type: 'AWS::ApiGateway::Resource'
Properties:
RestApiId: !Ref MyRestApi
ParentId: !GetAtt
- MyRestApi
- RootResourceId
PathPart: charges
Restapiresource2:
Type: 'AWS::ApiGateway::Resource'
Properties:
RestApiId: !Ref MyRestApi
ParentId: !GetAtt
- MyRestApi
- RootResourceId
PathPart: online-count
Method:
Type: AWS::ApiGateway::Method
Properties:
HttpMethod: POST
ResourceId: !Ref Restapiresource
RestApiId: !Ref MyRestApi
AuthorizationType: NONE
Method2:
Type: AWS::ApiGateway::Method
Properties:
HttpMethod: GET
ResourceId: !Ref Restapiresource2
RestApiId: !Ref MyRestApi
AuthorizationType: NONE
Integration:
IntegrationHttpMethod: "POST"
Type: "AWS"
Uri: !Sub
- "arn:aws:apigateway:${AWS::Region}:lambda:path/2015-03-31/functions/${lambdaArn}/invocations"
- lambdaArn: !GetAtt "lambdaFunction.Arn"
ResourceId: !Ref Restapiresource2
RestApiId: !Ref MyRestApi