使用aws-cli创建api-gateway lambda集成 [英] Create api-gateway lambda integration using aws-cli
问题描述
我需要使用aws客户端创建一个api网关.我使用Web控制台成功创建并与aws-lambda函数集成.但是我对aws-client感到困惑.这些是我遵循的步骤.
I need to create an api gateway using aws client. I successfully create and integrate with my aws-lambda function using web console. But I am confused with aws-client. These are the steps I followed.
- 创建api网关并使用Web控制台与我的示例lambda函数集成.
- 部署创建的api并导出为json文件.
-
使用aws-cli使用导出的json文件创建新的api网关.这样的命令.
- Deploy created api and export as json file.
Create new api gateway using exported json file using aws-cli. Command like this.
aws apigateway import-rest-api --body file://tmpfile.json --region us-east-1;
但是它仅创建资源&方法.
But it created only resources & methods.
-
为了将api方法与我的lambda函数集成在一起,我执行这样的命令
For integrate api method with my lambda function, I execute command like this
aws apigateway put-integration --rest-api-id 42ku123id8u3a --resource-id core-api-dev --http-method DELETE --type AWS --integration-http-method POST --uri 'arn:aws:lambda:us-east-1:my-lambda-function-arn' --region us-east-1
但是它会产生这样的错误消息
But it produces error message like this
调用PutIntegration操作时发生错误(NotFoundException):指定了无效的资源标识符
An error occurred (NotFoundException) when calling the PutIntegration operation: Invalid Resource identifier specified
是否可以使用aws客户端将api网关方法与现有的lambda函数集成在一起?什么是资源标识符?
Is it possible to integrate api gateway method with existing lambda function using aws client? What is Resource identifier?
推荐答案
您可以运行aws apigateway get-resources
来获取resource-id
aws apigateway get-resources --rest-api-id 42ku123id8u3a --region us-east-1
它将返回JSon之类的
It will return a JSon like
{
"items": [
{
"path": "/resource/xxx",
"resourceMethods": {
"POST": {}
},
"id": "_yourresourceid_",
"pathPart": "xxx",
"parentId": "ai5b02"
}
]
}
您可以从此JSon中获取 id 并将其用于aws apigateway put-integration
you can take the id from this JSon and use it on your command for aws apigateway put-integration
这篇关于使用aws-cli创建api-gateway lambda集成的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!