Closed RikuTheFuffs closed 10 months ago
Hi @RikuTheFuffs 👋 thanks for reaching out!
I believe you'll need to provide a payload
value for your function.
When API Gateway invoked Lambda, it provides a structured payload that includes all the HTTP request details (body, headers, etc.). You can find the full payload schema here: https://docs.aws.amazon.com/apigateway/latest/developerguide/http-api-develop-integrations-lambda.html
Just make sure to provide Lambda Power Tuning with the payload you function expects. Is it a GET request with a querystring parameter? Or is it a POST request with a JSON body?
You can also use AWS SAM to generate sample payload.
I hope this helps :)
Hi @alexcasalboni thanks for the help! I followed your advice, installed sam and generated a sample payload for apigateway, but I'm still unable to test the function with the tool.
Let me provide additional context:
/users/decks
, so the full address is https://<LambdaAddress>/api/users/decks
Using the sam tool you provided, I generated this payload:
{
"version": "2.0",
"routeKey": "$default",
"rawPath": "/path/to/resource",
"rawQueryString": "parameter1=value1¶meter1=value2¶meter2=value",
"cookies": [
"cookie1",
"cookie2"
],
"headers": {
"Header1": "value1",
"Header2": "value1,value2"
},
"queryStringParameters": {
"parameter1": "value1,value2",
"parameter2": "value"
},
"requestContext": {
"accountId": "123456789012",
"apiId": "api-id",
"authentication": {
"clientCert": {
"clientCertPem": "CERT_CONTENT",
"subjectDN": "www.example.com",
"issuerDN": "Example issuer",
"serialNumber": "a1:a1:a1:a1:a1:a1:a1:a1:a1:a1:a1:a1:a1:a1:a1:a1",
"validity": {
"notBefore": "May 28 12:30:02 2019 GMT",
"notAfter": "Aug 5 09:36:04 2021 GMT"
}
}
},
"authorizer": {
"jwt": {
"claims": {
"claim1": "value1",
"claim2": "value2"
},
"scopes": [
"scope1",
"scope2"
]
}
},
"domainName": "id.execute-api.us-east-1.amazonaws.com",
"domainPrefix": "id",
"http": {
"method": "GET",
"path": "/users/decks",
"protocol": "HTTP/1.1",
"sourceIp": "192.168.0.1/32",
"userAgent": "agent"
},
"requestId": "id",
"routeKey": "$default",
"stage": "$default",
"time": "12/Mar/2020:19:03:58 +0000",
"timeEpoch": 1583348638390
},
"body": "eyJ0ZXN0IjoiYm9keSJ9",
"pathParameters": {
"parameter1": "value1"
},
"isBase64Encoded": true,
"stageVariables": {
"stageVariable1": "value1",
"stageVariable2": "value2"
}
}
I added it to the input:
{
"input": {
"lambdaARN": "arn:aws:lambda:eu-west-1:446041730441:function:MyHttpGatewayApi-AspNetCoreFunction-1JLIZ7WF6RFXN",
"powerValues": [
128,
256,
512,
1024,
2048,
3008
],
"num": 10,
"payload": "{\r\n \"version\": \"2.0\",\r\n \"routeKey\": \"$default\",\r\n \"rawPath\": \"/path/to/resource\",\r\n \"rawQueryString\": \"parameter1=value1¶meter1=value2¶meter2=value\",\r\n \"cookies\": [\r\n \"cookie1\",\r\n \"cookie2\"\r\n ],\r\n \"headers\": {\r\n \"Header1\": \"value1\",\r\n \"Header2\": \"value1,value2\"\r\n },\r\n \"queryStringParameters\": {\r\n \"parameter1\": \"value1,value2\",\r\n \"parameter2\": \"value\"\r\n },\r\n \"requestContext\": {\r\n \"accountId\": \"123456789012\",\r\n \"apiId\": \"api-id\",\r\n \"authentication\": {\r\n \"clientCert\": {\r\n \"clientCertPem\": \"CERT_CONTENT\",\r\n \"subjectDN\": \"www.example.com\",\r\n \"issuerDN\": \"Example issuer\",\r\n \"serialNumber\": \"a1:a1:a1:a1:a1:a1:a1:a1:a1:a1:a1:a1:a1:a1:a1:a1\",\r\n \"validity\": {\r\n \"notBefore\": \"May 28 12:30:02 2019 GMT\",\r\n \"notAfter\": \"Aug 5 09:36:04 2021 GMT\"\r\n }\r\n }\r\n },\r\n \"authorizer\": {\r\n \"jwt\": {\r\n \"claims\": {\r\n \"claim1\": \"value1\",\r\n \"claim2\": \"value2\"\r\n },\r\n \"scopes\": [\r\n \"scope1\",\r\n \"scope2\"\r\n ]\r\n }\r\n },\r\n \"domainName\": \"id.execute-api.us-east-1.amazonaws.com\",\r\n \"domainPrefix\": \"id\",\r\n \"http\": {\r\n \"method\": \"GET\",\r\n \"path\": \"/users/decks\",\r\n \"protocol\": \"HTTP/1.1\",\r\n \"sourceIp\": \"192.168.0.1/32\",\r\n \"userAgent\": \"agent\"\r\n },\r\n \"requestId\": \"id\",\r\n \"routeKey\": \"$default\",\r\n \"stage\": \"$default\",\r\n \"time\": \"12/Mar/2020:19:03:58 +0000\",\r\n \"timeEpoch\": 1583348638390\r\n },\r\n \"body\": \"eyJ0ZXN0IjoiYm9keSJ9\",\r\n \"pathParameters\": {\r\n \"parameter1\": \"value1\"\r\n },\r\n \"isBase64Encoded\": true,\r\n \"stageVariables\": {\r\n \"stageVariable1\": \"value1\",\r\n \"stageVariable2\": \"value2\"\r\n }\r\n}",
"parallelInvocation": false,
"strategy": "speed"
},
"value": 512
}
And executed again. Now I get this error about a PEM certificate:
{
"errorType": "Error",
"errorMessage": "Invocation error (running in series): {\n \"errorType\": \"InvalidOperationException\",\n \"errorMessage\": \"Client certificate PEM was invalid. Expected to start with '-----BEGIN CERTIFICATE-----' and end with '-----END CERTIFICATE-----'.\",\n \"stackTrace\": [\n \"at Amazon.Lambda.AspNetCoreServer.Internal.Utilities.GetX509Certificate2FromPem(String clientCertPem)\",\n \"at Amazon.Lambda.AspNetCoreServer.APIGatewayHttpApiV2ProxyFunction.MarshallRequest(InvokeFeatures features, APIGatewayHttpApiV2ProxyRequest apiGatewayRequest, ILambdaContext lambdaContext)\",\n \"at Amazon.Lambda.AspNetCoreServer.AbstractAspNetCoreFunction`2.FunctionHandlerAsync(TREQUEST request, ILambdaContext lambdaContext)\",\n \"at MyHttpGatewayApi.LambdaEntryPoint.FunctionHandlerAsync(APIGatewayHttpApiV2ProxyRequest request, ILambdaContext lambdaContext)\",\n \"at lambda_method1(Closure , Stream , ILambdaContext , Stream )\",\n \"at Amazon.Lambda.RuntimeSupport.Bootstrap.UserCodeLoader.Invoke(Stream lambdaData, ILambdaContext lambdaContext, Stream outStream) in /src/Repo/Libraries/src/Amazon.Lambda.RuntimeSupport/Bootstrap/UserCodeLoader.cs:line 145\",\n \"at Amazon.Lambda.RuntimeSupport.HandlerWrapper.<>c__DisplayClass8_0.<GetHandlerWrapper>b__0(InvocationRequest invocation) in /src/Repo/Libraries/src/Amazon.Lambda.RuntimeSupport/Bootstrap/HandlerWrapper.cs:line 55\",\n \"at Amazon.Lambda.RuntimeSupport.LambdaBootstrap.InvokeOnceAsync(CancellationToken cancellationToken) in /src/Repo/Libraries/src/Amazon.Lambda.RuntimeSupport/Bootstrap/LambdaBootstrap.cs:line 176\"\n ]\n}\n with payload \"{\\r\\n \\\"version\\\": \\\"2.0\\\",\\r\\n \\\"routeKey\\\": \\\"$default\\\",\\r\\n \\\"rawPath\\\": \\\"/path/to/resource\\\",\\r\\n \\\"rawQueryString\\\": \\\"parameter1=value1¶meter1=value2¶meter2=value\\\",\\r\\n \\\"cookies\\\": [\\r\\n \\\"cookie1\\\",\\r\\n \\\"cookie2\\\"\\r\\n ],\\r\\n \\\"headers\\\": {\\r\\n \\\"Header1\\\": \\\"value1\\\",\\r\\n \\\"Header2\\\": \\\"value1,value2\\\"\\r\\n },\\r\\n \\\"queryStringParameters\\\": {\\r\\n \\\"parameter1\\\": \\\"value1,value2\\\",\\r\\n \\\"parameter2\\\": \\\"value\\\"\\r\\n },\\r\\n \\\"requestContext\\\": {\\r\\n \\\"accountId\\\": \\\"123456789012\\\",\\r\\n \\\"apiId\\\": \\\"api-id\\\",\\r\\n \\\"authentication\\\": {\\r\\n \\\"clientCert\\\": {\\r\\n \\\"clientCertPem\\\": \\\"CERT_CONTENT\\\",\\r\\n \\\"subjectDN\\\": \\\"www.example.com\\\",\\r\\n \\\"issuerDN\\\": \\\"Example issuer\\\",\\r\\n \\\"serialNumber\\\": \\\"a1:a1:a1:a1:a1:a1:a1:a1:a1:a1:a1:a1:a1:a1:a1:a1\\\",\\r\\n \\\"validity\\\": {\\r\\n \\\"notBefore\\\": \\\"May 28 12:30:02 2019 GMT\\\",\\r\\n \\\"notAfter\\\": \\\"Aug 5 09:36:04 2021 GMT\\\"\\r\\n }\\r\\n }\\r\\n },\\r\\n \\\"authorizer\\\": {\\r\\n \\\"jwt\\\": {\\r\\n \\\"claims\\\": {\\r\\n \\\"claim1\\\": \\\"value1\\\",\\r\\n \\\"claim2\\\": \\\"value2\\\"\\r\\n },\\r\\n \\\"scopes\\\": [\\r\\n \\\"scope1\\\",\\r\\n \\\"scope2\\\"\\r\\n ]\\r\\n }\\r\\n },\\r\\n \\\"domainName\\\": \\\"id.execute-api.us-east-1.amazonaws.com\\\",\\r\\n \\\"domainPrefix\\\": \\\"id\\\",\\r\\n \\\"http\\\": {\\r\\n \\\"method\\\": \\\"GET\\\",\\r\\n \\\"path\\\": \\\"/users/decks\\\",\\r\\n \\\"protocol\\\": \\\"HTTP/1.1\\\",\\r\\n \\\"sourceIp\\\": \\\"192.168.0.1/32\\\",\\r\\n \\\"userAgent\\\": \\\"agent\\\"\\r\\n },\\r\\n \\\"requestId\\\": \\\"id\\\",\\r\\n \\\"routeKey\\\": \\\"$default\\\",\\r\\n \\\"stage\\\": \\\"$default\\\",\\r\\n \\\"time\\\": \\\"12/Mar/2020:19:03:58 +0000\\\",\\r\\n \\\"timeEpoch\\\": 1583348638390\\r\\n },\\r\\n \\\"body\\\": \\\"eyJ0ZXN0IjoiYm9keSJ9\\\",\\r\\n \\\"pathParameters\\\": {\\r\\n \\\"parameter1\\\": \\\"value1\\\"\\r\\n },\\r\\n \\\"isBase64Encoded\\\": true,\\r\\n \\\"stageVariables\\\": {\\r\\n \\\"stageVariable1\\\": \\\"value1\\\",\\r\\n \\\"stageVariable2\\\": \\\"value2\\\"\\r\\n }\\r\\n}\"",
"trace": [
"Error: Invocation error (running in series): {",
" \"errorType\": \"InvalidOperationException\",",
" \"errorMessage\": \"Client certificate PEM was invalid. Expected to start with '-----BEGIN CERTIFICATE-----' and end with '-----END CERTIFICATE-----'.\",",
" \"stackTrace\": [",
" \"at Amazon.Lambda.AspNetCoreServer.Internal.Utilities.GetX509Certificate2FromPem(String clientCertPem)\",",
" \"at Amazon.Lambda.AspNetCoreServer.APIGatewayHttpApiV2ProxyFunction.MarshallRequest(InvokeFeatures features, APIGatewayHttpApiV2ProxyRequest apiGatewayRequest, ILambdaContext lambdaContext)\",",
" \"at Amazon.Lambda.AspNetCoreServer.AbstractAspNetCoreFunction`2.FunctionHandlerAsync(TREQUEST request, ILambdaContext lambdaContext)\",",
" \"at MyHttpGatewayApi.LambdaEntryPoint.FunctionHandlerAsync(APIGatewayHttpApiV2ProxyRequest request, ILambdaContext lambdaContext)\",",
" \"at lambda_method1(Closure , Stream , ILambdaContext , Stream )\",",
" \"at Amazon.Lambda.RuntimeSupport.Bootstrap.UserCodeLoader.Invoke(Stream lambdaData, ILambdaContext lambdaContext, Stream outStream) in /src/Repo/Libraries/src/Amazon.Lambda.RuntimeSupport/Bootstrap/UserCodeLoader.cs:line 145\",",
" \"at Amazon.Lambda.RuntimeSupport.HandlerWrapper.<>c__DisplayClass8_0.<GetHandlerWrapper>b__0(InvocationRequest invocation) in /src/Repo/Libraries/src/Amazon.Lambda.RuntimeSupport/Bootstrap/HandlerWrapper.cs:line 55\",",
" \"at Amazon.Lambda.RuntimeSupport.LambdaBootstrap.InvokeOnceAsync(CancellationToken cancellationToken) in /src/Repo/Libraries/src/Amazon.Lambda.RuntimeSupport/Bootstrap/LambdaBootstrap.cs:line 176\"",
" ]",
"}",
" with payload \"{\\r\\n \\\"version\\\": \\\"2.0\\\",\\r\\n \\\"routeKey\\\": \\\"$default\\\",\\r\\n \\\"rawPath\\\": \\\"/path/to/resource\\\",\\r\\n \\\"rawQueryString\\\": \\\"parameter1=value1¶meter1=value2¶meter2=value\\\",\\r\\n \\\"cookies\\\": [\\r\\n \\\"cookie1\\\",\\r\\n \\\"cookie2\\\"\\r\\n ],\\r\\n \\\"headers\\\": {\\r\\n \\\"Header1\\\": \\\"value1\\\",\\r\\n \\\"Header2\\\": \\\"value1,value2\\\"\\r\\n },\\r\\n \\\"queryStringParameters\\\": {\\r\\n \\\"parameter1\\\": \\\"value1,value2\\\",\\r\\n \\\"parameter2\\\": \\\"value\\\"\\r\\n },\\r\\n \\\"requestContext\\\": {\\r\\n \\\"accountId\\\": \\\"123456789012\\\",\\r\\n \\\"apiId\\\": \\\"api-id\\\",\\r\\n \\\"authentication\\\": {\\r\\n \\\"clientCert\\\": {\\r\\n \\\"clientCertPem\\\": \\\"CERT_CONTENT\\\",\\r\\n \\\"subjectDN\\\": \\\"www.example.com\\\",\\r\\n \\\"issuerDN\\\": \\\"Example issuer\\\",\\r\\n \\\"serialNumber\\\": \\\"a1:a1:a1:a1:a1:a1:a1:a1:a1:a1:a1:a1:a1:a1:a1:a1\\\",\\r\\n \\\"validity\\\": {\\r\\n \\\"notBefore\\\": \\\"May 28 12:30:02 2019 GMT\\\",\\r\\n \\\"notAfter\\\": \\\"Aug 5 09:36:04 2021 GMT\\\"\\r\\n }\\r\\n }\\r\\n },\\r\\n \\\"authorizer\\\": {\\r\\n \\\"jwt\\\": {\\r\\n \\\"claims\\\": {\\r\\n \\\"claim1\\\": \\\"value1\\\",\\r\\n \\\"claim2\\\": \\\"value2\\\"\\r\\n },\\r\\n \\\"scopes\\\": [\\r\\n \\\"scope1\\\",\\r\\n \\\"scope2\\\"\\r\\n ]\\r\\n }\\r\\n },\\r\\n \\\"domainName\\\": \\\"id.execute-api.us-east-1.amazonaws.com\\\",\\r\\n \\\"domainPrefix\\\": \\\"id\\\",\\r\\n \\\"http\\\": {\\r\\n \\\"method\\\": \\\"GET\\\",\\r\\n \\\"path\\\": \\\"/users/decks\\\",\\r\\n \\\"protocol\\\": \\\"HTTP/1.1\\\",\\r\\n \\\"sourceIp\\\": \\\"192.168.0.1/32\\\",\\r\\n \\\"userAgent\\\": \\\"agent\\\"\\r\\n },\\r\\n \\\"requestId\\\": \\\"id\\\",\\r\\n \\\"routeKey\\\": \\\"$default\\\",\\r\\n \\\"stage\\\": \\\"$default\\\",\\r\\n \\\"time\\\": \\\"12/Mar/2020:19:03:58 +0000\\\",\\r\\n \\\"timeEpoch\\\": 1583348638390\\r\\n },\\r\\n \\\"body\\\": \\\"eyJ0ZXN0IjoiYm9keSJ9\\\",\\r\\n \\\"pathParameters\\\": {\\r\\n \\\"parameter1\\\": \\\"value1\\\"\\r\\n },\\r\\n \\\"isBase64Encoded\\\": true,\\r\\n \\\"stageVariables\\\": {\\r\\n \\\"stageVariable1\\\": \\\"value1\\\",\\r\\n \\\"stageVariable2\\\": \\\"value2\\\"\\r\\n }\\r\\n}\"",
" at runInSeries (/var/task/executor.js:162:19)",
" at processTicksAndRejections (node:internal/process/task_queues:96:5)",
" at async Runtime.module.exports.handler (/var/task/executor.js:69:19)"
]
}
1) What am I doing wrong? 2) Do I actually need to send all that payload?
Thanks in advance for your support!
@RikuTheFuffs it's possible that the .NET utility is trying to validate the HTTPS certificate for id.execute-api.us-east-1.amazonaws.com
. Is your function deployed in us-east-1
?
Anyways, I would recommend to
This will ensure that you're using exactly the payload that your function expects, without any unnecessary parameters.
hey @RikuTheFuffs 👋 did you manage to fix (or work around) this?
I don't think it's an issue with Lambda Power Tuning itself, so I'll close this issue for now.
Please do let me know if you still need help to generate the correct test payload for your function :)
I have a working .NET 6 app that I'm trying to optimize. I'm using the power-tuning tool to test where the startup bottleneck is, but when I try to exewcute it the lambda throws.
I'm running the lambda with this input:
This is the output:
This is how the graph looks like:
Looking at the stack trace in the execution log, and googling the MarshallRequest nullreference in it, it seems that it fails because of some interactions between the APIGateway and the Lambda uses APIGatewayHttpApiV2ProxyFunction. There should be a "Use Lambda Proxy integration" option somewhere to enable in the API Gateway, but I couldn't find it anywhere :(
Unfortunately I'm not really familiar with this tool.
What steps should I try next, to be able to test my function?