- html - 出于某种原因,IE8 对我的 Sass 文件中继承的 html5 CSS 不友好?
- JMeter 在响应断言中使用 span 标签的问题
- html - 在 :hover and :active? 上具有不同效果的 CSS 动画
- html - 相对于居中的 html 内容固定的 CSS 重复背景?
我正在使用 cloudformation 定义一个 api 网关,该网关定义了 4 个方法:GET、POST、PUT 和 DELETE。
我想使用这 4 个方法来触发我的 lambda。当部署此模板时。 lambda 仅显示 API 网关的 DELETE 方法。
如何在 cloudformation 中定义我的 lambda,以便它将采用所有 4 种方法?
Resources:
lambdaExecutionRole:
Type: "AWS::IAM::Role"
Properties:
Path: /
AssumeRolePolicyDocument:
Version: 2012-10-17
Statement:
- Effect: Allow
Principal:
Service:
- lambda.amazonaws.com
Action:
- sts:AssumeRole
ManagedPolicyArns:
- !Sub "arn:${AWS::Partition}:iam::aws:policy/service-role/AWSLambdaVPCAccessExecutionRole"
lambdaFunction:
Type: AWS::Lambda::Function
Properties:
FunctionName: !Ref AWS::StackName
VpcConfig:
SubnetIds:
- {"Fn::ImportValue": !Sub "${networkStackName}-${AWS::Region}-privateSubnetAZ1"}
- {"Fn::ImportValue": !Sub "${networkStackName}-${AWS::Region}-privateSubnetAZ2"}
SecurityGroupIds:
- {"Fn::ImportValue": !Sub "${securityStackName}-${AWS::Region}-sgDNSRestrictedAccess"}
Runtime: dotnetcore2.1
Handler: MY::LAMBDA.HANDLER::NAME
MemorySize: 128
Role: !GetAtt lambdaExecutionRole.Arn
Timeout: 30
Code:
S3Bucket: bucket-name
S3Key: bucket-key.zip
lambdaInvokePermission:
Type: "AWS::Lambda::Permission"
Properties:
FunctionName: !Sub "arn:${AWS::Partition}:lambda:${AWS::Region}:${AWS::AccountId}:function:${AWS::StackName}"
Action: 'lambda:InvokeFunction'
Principal: apigateway.amazonaws.com
SourceArn: !Sub "arn:${AWS::Partition}:execute-api:${AWS::Region}:${AWS::AccountId}:${apiGatewayRestApi}/*"
DependsOn:
- lambdaFunction
apiGatewayRestApi:
Type: "AWS::ApiGateway::RestApi"
Properties:
Name: !Ref AWS::StackName
EndpointConfiguration:
Types:
- REGIONAL
apiGatewayResourcePath:
Type: "AWS::ApiGateway::Resource"
Properties:
RestApiId: !Ref apiGatewayRestApi
ParentId: !GetAtt
- apiGatewayRestApi
- RootResourceId
PathPart: !Ref apiGatewayProxyPath
DependsOn:
- apiGatewayRestApi
apiGatewayPostMethod:
Type: "AWS::ApiGateway::Method"
Properties:
RestApiId: !Ref apiGatewayRestApi
ResourceId: !Ref apiGatewayResourcePath
HttpMethod: POST
AuthorizationType: NONE
Integration:
Type: AWS_PROXY
IntegrationHttpMethod: POST
Uri: !Join
- ":"
- - "arn"
- !Ref AWS::Partition
- "apigateway"
- !Ref AWS::Region
- "lambda:path/2015-03-31/functions/arn"
- !Ref AWS::Partition
- "lambda"
- !Ref AWS::Region
- !Ref AWS::AccountId
- "function"
- !Join
- "/"
- - !Sub "${AWS::StackName}"
- "invocations"
DependsOn:
- apiGatewayResourcePath
apiGatewayGetMethod:
Type: "AWS::ApiGateway::Method"
Properties:
RestApiId: !Ref apiGatewayRestApi
ResourceId: !Ref apiGatewayResourcePath
HttpMethod: GET
AuthorizationType: NONE
Integration:
Type: AWS_PROXY
IntegrationHttpMethod: GET
Uri: !Join
- ":"
- - "arn"
- !Ref AWS::Partition
- "apigateway"
- !Ref AWS::Region
- "lambda:path/2015-03-31/functions/arn"
- !Ref AWS::Partition
- "lambda"
- !Ref AWS::Region
- !Ref AWS::AccountId
- "function"
- !Join
- "/"
- - !Sub "${AWS::StackName}"
- "invocations"
DependsOn:
- apiGatewayResourcePath
apiGatewayPutMethod:
Type: "AWS::ApiGateway::Method"
Properties:
RestApiId: !Ref apiGatewayRestApi
ResourceId: !Ref apiGatewayResourcePath
HttpMethod: PUT
AuthorizationType: NONE
Integration:
Type: AWS_PROXY
IntegrationHttpMethod: PUT
Uri: !Join
- ":"
- - "arn"
- !Ref AWS::Partition
- "apigateway"
- !Ref AWS::Region
- "lambda:path/2015-03-31/functions/arn"
- !Ref AWS::Partition
- "lambda"
- !Ref AWS::Region
- !Ref AWS::AccountId
- "function"
- !Join
- "/"
- - !Sub "${AWS::StackName}"
- "invocations"
DependsOn:
- apiGatewayResourcePath
apiGatewayDeleteMethod:
Type: "AWS::ApiGateway::Method"
Properties:
RestApiId: !Ref apiGatewayRestApi
ResourceId: !Ref apiGatewayResourcePath
HttpMethod: DELETE
AuthorizationType: NONE
Integration:
Type: AWS_PROXY
IntegrationHttpMethod: DELETE
Uri: !Join
- ":"
- - "arn"
- !Ref AWS::Partition
- "apigateway"
- !Ref AWS::Region
- "lambda:path/2015-03-31/functions/arn"
- !Ref AWS::Partition
- "lambda"
- !Ref AWS::Region
- !Ref AWS::AccountId
- "function"
- !Join
- "/"
- - !Sub "${AWS::StackName}"
- "invocations"
DependsOn:
- apiGatewayResourcePath
apiGatewayDeployment:
Type: "AWS::ApiGateway::Deployment"
Properties:
RestApiId: !Ref apiGatewayRestApi
DependsOn:
- apiGatewayPostMethod
- apiGatewayGetMethod
- apiGatewayDeleteMethod
- apiGatewayPutMethod
apiGatewayStage:
Type: "AWS::ApiGateway::Stage"
Properties:
StageName: app
RestApiId: !Ref apiGatewayRestApi
DeploymentId: !Ref apiGatewayDeployment
MethodSettings:
- ResourcePath: !Sub "/${apiGatewayProxyPath}"
HttpMethod: POST
MetricsEnabled: true
LoggingLevel: INFO
- ResourcePath: !Sub "/${apiGatewayProxyPath}"
HttpMethod: GET
MetricsEnabled: true
LoggingLevel: INFO
- ResourcePath: !Sub "/${apiGatewayProxyPath}"
HttpMethod: PUT
MetricsEnabled: true
LoggingLevel: INFO
- ResourcePath: !Sub "/${apiGatewayProxyPath}"
HttpMethod: DELETE
MetricsEnabled: true
LoggingLevel: INFO
DependsOn:
- apiGatewayDeployment
最佳答案
对于 Lambda 代理
集成,IntegrationHttpMethod
始终为 POST
。请参阅lambda proxy integration - step 5
Important
For Lambda integrations, you must use the HTTP method of POST for the integration request, according to the specification of the Lambda service action for function invocations. The IAM role of apigAwsProxyRole must have policies allowing the apigateway service to invoke Lambda functions. For more information about IAM permissions, see API Gateway Permissions Model for Invoking an API.
所以你的例子GET 方法集成应该如下所示
apiGatewayGetMethod:
Type: "AWS::ApiGateway::Method"
Properties:
RestApiId: !Ref apiGatewayRestApi
ResourceId: !Ref apiGatewayResourcePath
HttpMethod: GET
AuthorizationType: NONE
Integration:
Type: AWS_PROXY
IntegrationHttpMethod: POST
Uri: !Join
- ":"
- - "arn"
- !Ref AWS::Partition
- "apigateway"
- !Ref AWS::Region
- "lambda:path/2015-03-31/functions/arn"
- !Ref AWS::Partition
- "lambda"
- !Ref AWS::Region
- !Ref AWS::AccountId
- "function"
- !Join
- "/"
- - !Sub "${AWS::StackName}"
- "invocations"
DependsOn:
- apiGatewayResourcePath
关于aws-lambda - 如何使用多种方法从API网关触发AWS Lambda?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/55454744/
可以使用 lambda 和函数创建有序对(Lisp 中的缺点),如 Use of lambda for cons/car/cdr definition in SICP 所示。 它也适用于 Python
我正在尝试从另一个调用一个 AWS lambda 并执行 lambda 链接。这样做的理由是 AWS 不提供来自同一个 S3 存储桶的多个触发器。 我创建了一个带有 s3 触发器的 lambda。第一
根据以下源代码,常规 lambda 似乎可以与扩展 lambda 互换。 fun main(args: Array) { val numbers = listOf(1, 2, 3) f
A Tutorial Introduction to the Lambda Calculus 本文介绍乘法函数 The multiplication of two numbers x and y ca
我想弄清楚如何为下面的表达式绘制语法树。首先,这究竟是如何表现的?看样子是以1和2为参数,如果n是 0,它只会返回 m . 另外,有人可以指出解析树的开始,还是一个例子?我一直找不到一个。 最佳答案
在 C++0x 中,我想知道 lambda 函数的类型是什么。具体来说: #include type1 foo(int x){ return [x](int y)->int{return x * y
我在其中一个职位发布中看到了这个问题,它询问什么是 lambda 函数以及它与高阶函数的关系。我已经知道如何使用 lambda 函数,但不太自信地解释它,所以我做了一点谷歌搜索,发现了这个:What
很难说出这里问的是什么。这个问题是含糊的、模糊的、不完整的、过于宽泛的或修辞性的,无法以目前的形式得到合理的回答。如需帮助澄清此问题以便重新打开它,visit the help center 。 已关
Evaluate (((lambda(x y) (lambda (x) (* x y))) 5 6) 10) in Scheme. 我不知道实际上该怎么做! ((lambda (x y) (+ x x
我正在处理 MyCustomType 的实例集合如下: fun runAll(vararg commands: MyCustomType){ commands.forEach { it.myM
Brian 在他对问题 "Are side effects a good thing?" 的论证中的前提很有趣: computers are von-Neumann machines that are
在 Common Lisp 中,如果我希望两个函数共享状态,我将按如下方式执行 let over lambda: (let ((state 1)) (defun inc-state () (in
Evaluate (((lambda(x y) (lambda (x) (* x y))) 5 6) 10) in Scheme. 我不知道实际上该怎么做! ((lambda (x y) (+ x x
作为lambda calculus wiki说: There are several possible ways to define the natural numbers in lambda cal
我有一个数据类,我需要初始化一些 List .我需要获取 JsonArray 的值(我使用的是 Gson)。 我做了这个函数: private fun arrayToList(data: JsonAr
((lambda () )) 的方案中是否有简写 例如,代替 ((lambda () (define x 1) (display x))) 我希望能够做类似的事情 (empty-lam
我在 Java library 中有以下方法: public void setColumnComparator(final int columnIndex, final Comparator colu
我正在研究一个函数来计算国际象棋游戏中棋子的有效移动。 white-pawn-move 函数有效。当我试图将其概括为任一玩家的棋子 (pawn-move) 时,我遇到了非法函数调用。我已经在 repl
考虑这段代码(在 GCC 和 MSVC 上编译): int main() { auto foo = [](auto p){ typedef decltype(p) p_t;
我正在阅读一个在 lambda 内部使用 lambda 的片段,然后我想通过创建一个虚拟函数来测试它,该函数从文件中读取然后返回最大和最小数字。 这是我想出来的 dummy = lambda path
我是一名优秀的程序员,十分优秀!