如何正确配置lambda函数PROFISIONEDCONCURRENTEXECTICTS?
我具有与API网关集成的Lambda函数。我正在尝试为该功能配置provisionedConcurrentExecutions
而不会成功。云手表包含以下日志记录:
报告请求ID:6D818A07-CEE8-41F8-AEDC-9DF9B2AA1A75持续时间: 4276.27 MS计费持续时间:4277 MS内存尺寸:256 MB最大内存:107 MB Init持续时间:3536.87 MS
如我所知,如果provisionedconcurrentexections
是正确配置的不在那里。
我是唯一打电话给该功能的人,因此只有一个并发请求。
我正在使用AWS CDK配置API GATWAY和功能。这是代码:
import { Duration, Stack, StackProps } from 'aws-cdk-lib';
import { Construct } from 'constructs';
import * as lambda from 'aws-cdk-lib/aws-lambda'
import { LambdaIntegration, RestApi } from 'aws-cdk-lib/aws-apigateway';
export class ApiLambdaStack extends Stack {
constructor(scope: Construct, id: string, props: StackProps) {
super(scope, id, props);
const api = new RestApi(this, 'OpenDataApi', {
restApiName: `REST API`
});
this.configureLambda(api, "MyLambdaFunction", "my-lambda-function");
}
private configureLambda(api: RestApi, methodName: string, path: string, memorySize: number = 256): void {
const lambdaFunction = new lambda.Function(this, `${methodName}LambdaFunction`, {
runtime: lambda.Runtime.DOTNET_6,
handler: `ApiGatewayLambda::ApiGatewayLambda.Functions::${methodName}`,
code: lambda.Code.fromAsset('ApiGatewayLambda'),
timeout: Duration.seconds(30),
memorySize: memorySize,
reservedConcurrentExecutions: 4
});
const version = lambdaFunction.currentVersion;
const alias = new lambda.Alias(this, `${methodName}Al`, {
aliasName: `${methodName}Al`,
version: version,
provisionedConcurrentExecutions: 2
});
const lambdaFunctionIntegration = new LambdaIntegration(alias);
const resource = api.root.addResource(path);
resource.addMethod('POST', lambdaFunctionIntegration);
}
}
我错过了什么吗?如何正确配置provisionedConcurrentExecutions
?
我正在使用Postman来调用API网关,第一个请求大约需要10秒,后续请求不到1秒钟。如果我等待一些时间,那又需要10秒。因此,出了问题,配置并发似乎并没有产生任何效果。
I have a lambda function integrated with API Gateway. I'm trying to configure provisionedConcurrentExecutions
for that function without success. Cloud Watch contains the following log record:
REPORT RequestId: 6d818a07-cee8-41f8-aedc-9df9b2aa1a75 Duration:
4276.27 ms Billed Duration: 4277 ms Memory Size: 256 MB Max Memory Used: 107 MB Init Duration: 3536.87 ms
As I understand, if provisionedConcurrentExecutions
is configured properly, Init Duration
should not be there.
I'm the only person calling the function, so there is only one concurrent request.
I'm using AWS CDK to configure the API Gatway and the function. Here is the code:
import { Duration, Stack, StackProps } from 'aws-cdk-lib';
import { Construct } from 'constructs';
import * as lambda from 'aws-cdk-lib/aws-lambda'
import { LambdaIntegration, RestApi } from 'aws-cdk-lib/aws-apigateway';
export class ApiLambdaStack extends Stack {
constructor(scope: Construct, id: string, props: StackProps) {
super(scope, id, props);
const api = new RestApi(this, 'OpenDataApi', {
restApiName: `REST API`
});
this.configureLambda(api, "MyLambdaFunction", "my-lambda-function");
}
private configureLambda(api: RestApi, methodName: string, path: string, memorySize: number = 256): void {
const lambdaFunction = new lambda.Function(this, `${methodName}LambdaFunction`, {
runtime: lambda.Runtime.DOTNET_6,
handler: `ApiGatewayLambda::ApiGatewayLambda.Functions::${methodName}`,
code: lambda.Code.fromAsset('ApiGatewayLambda'),
timeout: Duration.seconds(30),
memorySize: memorySize,
reservedConcurrentExecutions: 4
});
const version = lambdaFunction.currentVersion;
const alias = new lambda.Alias(this, `${methodName}Al`, {
aliasName: `${methodName}Al`,
version: version,
provisionedConcurrentExecutions: 2
});
const lambdaFunctionIntegration = new LambdaIntegration(alias);
const resource = api.root.addResource(path);
resource.addMethod('POST', lambdaFunctionIntegration);
}
}
Am I missing something? How to properly configure provisionedConcurrentExecutions
?
I'm using PostMan to call API Gateway, and the first request takes about 10 seconds, subsequent requests are under 1 second. If I wait some time, then it takes 10 seconds again. So something is wrong, provisioned concurrency doesn't seem to produce any effect.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论