ApiGateway 1 有一个别名,但它的接口不符合 V2:
这是domainName:
const domainName = new apigw2.DomainName(config.scope, config.id + 'DomainName', {
domainName: config.domainName,
certificate: config.certificate,
});
Run Code Online (Sandbox Code Playgroud) 我已经使用 SAM 部署了 API Gateway、Lambda 和 DynamoDB。lambda 函数的代码如下:
var AWS = require('aws-sdk');
exports.handler = async (event) => {
try {
console.log(event); //To check if there is any problem with the API call or not, (CloudWatch result = No issues)
console.log(event.body); // To confirm if the 'event' is a JSON object or not. (CloudWatch result = No issues)
var obj = JSON.parse(event.body);
console.log(obj.id);
console.log(obj.name);
var ID = obj.id;
var NAME = obj.name;
var ddb = new AWS.DynamoDB({apiVersion: '2012-08-10'});
var params = …Run Code Online (Sandbox Code Playgroud) amazon-web-services node.js amazon-dynamodb aws-lambda aws-api-gateway
我正在尝试将 Cognito Authorizer 添加到现有的 API Gateway LambdaRestApi。这是一个完整的代理集成,我希望授权者默认应用于所有方法。我从文档中看不到任何指示如何通过 CDK 完成此操作。
我拥有的:
const userPool = new cognito.UserPool(this, "TestUsers", {
userPoolName: "This is a test"
});
const proxyApi = new apig.LambdaRestApi(this, "HelloFoodSecureProxyApi", {
handler: proxyHandlerLambdaFunction
});
// proxyApi.addDefaultAuthorizor(userPool)
Run Code Online (Sandbox Code Playgroud)
据我所知,我将不得不恢复使用 raw RestApi,添加一个覆盖我的整个API的Resourceand Method,并使用类似的东西手动覆盖底层CFNGET_resource.add_property_override("AuthorizerId", {"Ref": authorizor.auth_id})
我错过了什么吗?有什么建议吗?如果我可以帮助的话,我宁愿不将我的整个 API(轻松地proxy转换为代码)解压到基础设施中。
我想要在 REST API 网关上导入 swagger JSON,但我收到了
Maximum number of Resources for this API has been reached. Please contact AWS if you need additional Resources.导入时的消息。我该怎么办,它说我需要额外的资源。我可以在 API Gateway 上添加其他资源。
我调用了连接到 Lambda 函数的 API 网关。我期望在处理程序的输入multiValueQueryStringParameters中看到一个键。event
https://aws.amazon.com/blogs/compute/support-for-multi-value-parameters-in-amazon-api-gateway/
相反,我看到了一个逗号分隔的列表queryStringParameters
例如,这个调用:
https://12324234234234.execute-api.us-east-2.amazonaws.com/dois_to_pmids?a=1&a=2&a=3
生成以下事件条目:
"queryStringParameters": {"a": "1,2,3"}
我尝试将所有内容都变成代理集成,首先要做的是:
GET /{proxy+}
然后通过执行以下操作:
ANY /{proxy+}
没有运气。
https://docs.aws.amazon.com/apigateway/latest/developerguide/api-gateway-set-up-simple-proxy.html
https://docs.aws.amazon.com/apigateway/latest/developerguide/set-up-lambda-proxy-integrations.html
这是怎么回事?
我创建了一个 AWS Websocket API 网关。它给了我一个终点,如下所示:
wss://**********.execute-api.**-*****-*.amazonaws.com/dev
Run Code Online (Sandbox Code Playgroud)
我需要将其更改为自定义域。这怎么办呢。我可以看到AWS提供的这个URL是wss协议URL。
请考虑以下代码(serverless.yml):
functions:
exportCvToPdf:
handler: handler.exportCvToPdf
timeout: 20
events:
- http:
path: export
method: post
Run Code Online (Sandbox Code Playgroud)
部署到 AWS 会返回指向 API 端点的链接。对端点进行 CURL 操作会返回:
{"message":"Missing Authentication Token"}
Run Code Online (Sandbox Code Playgroud)
如何使用无服务器框架创建公共端点?
我已经尝试过以下方法:
functions:
exportCvToPdf:
handler: handler.exportCvToPdf
timeout: 20
events:
- http:
path: export
method: post
authorizer: none # None NONE "none" "NONE" "None" has also been tried
Run Code Online (Sandbox Code Playgroud)
上面在部署时返回错误:
Function none doesn't exist in this Service
Run Code Online (Sandbox Code Playgroud) amazon-web-services aws-lambda aws-api-gateway serverless-framework
我在 AWS API Gateway 中有一个 REST API,它调用 Python Lambda 函数并返回一些结果。大多数情况下,此工作流程工作正常,这意味着执行 Lambda 函数并将结果传递回 API,API 又返回 200 OK 响应。
然而,有几次我从 API 收到 500 错误代码,而 Lambda 似乎甚至没有被执行。上面response.reason写着:“内部服务器错误”,并且没有给出其他信息。
对于 API 的失败请求和成功请求在方法或参数格式方面没有区别。
另一项评论是 API 启用了缓存设置。我看过类似的帖子,其中一些答案提到了 Lambda 函数返回的 JSON 对象的格式,其他答案则指出了 IAM 权限问题,但这些似乎都不是这里的原因。事实上,正如这篇文章的标题所说,这是一种间歇性行为:大多数时候它工作正常,但偶尔我会收到此错误。
任何提示将不胜感激。
我有一个 Lambda 函数,可以通过 api 网关访问。
如何让 CDK 添加映射模板,如下屏幕截图所示:
我尝试了多种变体:
....
const restApi = new apigateway.LambdaRestApi(this, "dyndns-api", {
handler: dyndnsLambda,
proxy: false,
domainName: {
domainName: siteDomain,
certificate: certificate,
endpointType: apigateway.EndpointType.REGIONAL
}
});
const methodResponse: apigateway.MethodResponse = {
statusCode: "200",
responseModels: {"application/json": apigateway.Model.EMPTY_MODEL}
}
const requestTemplate = {
"execution_mode" : "$input.params('mode')",
"source_ip" : "$context.identity.sourceIp",
"set_hostname" : "$input.params('hostname')",
"validation_hash" : "$input.params('hash')"
}
const dnydnsIntegration = new apigateway.LambdaIntegration(dyndnsLambda, {
allowTestInvoke: true,
passthroughBehavior: apigateway.PassthroughBehavior.WHEN_NO_TEMPLATES,
requestTemplates: { "application/json": JSON.stringify(requestTemplate) },
});
restApi.root.addMethod("GET", dnydnsIntegration, {
methodResponses: [methodResponse] …Run Code Online (Sandbox Code Playgroud) 我正在使用 CDK 配置 API 网关,但我正在努力处理 GET 方法请求中的 URL 查询字符串参数。我可以找到集成请求的示例,但找不到方法请求的示例。
这些是我使用控制台定义的 URL 查询字符串参数,我的问题是如何使用 CDK 在 TypeScript 中复制它?

我检查了CDK文档希望找到实现。我期望它可以在MethodOptions 接口下,但对我的情况没有任何用处。