aws-lambda-power-tuning: Bug: Support JSON logging

I attempted to run this using the serverless application repository deployment, which appears to be at version 4.3.3. The tags are as follows:

  • serverlessrepo:applicationId: arn:aws:serverlessrepo:us-east-1:451282441545:applications/aws-lambda-power-tuning
  • serverlessrepo:semanticVersion: 4.3.3

When it gets to the analyze step, the analyze lambda fails with the following error:

{
  "errorType": "TypeError",
  "errorMessage": "Cannot set properties of undefined (setting 'stateMachine')",
  "trace": [
    "TypeError: Cannot set properties of undefined (setting 'stateMachine')",
    "    at findOptimalConfiguration (/var/task/analyzer.js:54:26)",
    "    at Runtime.module.exports.handler (/var/task/analyzer.js:28:12)",
    "    at Runtime.handleOnceNonStreaming (file:///var/runtime/index.mjs:1173:29)"
  ]
}

I noticed that it appears that the executors failed to calculate any statistics, as all the results were 0 cost and 0 duration. Here is the full analyze step input:

{
  "lambdaARN": "arn:aws:lambda:us-west-2:12345:function:asdf",
  "powerValues": [
    128,
    256,
    512,
    1024,
    1536,
    2048,
    3008
  ],
  "num": 100,
  "payload": {
    "version": "2.0",
    "routeKey": "$default",
    "rawPath": "/",
    "rawQueryString": "",
    "headers": {
      "svix-signature": "v1,asdf=",
      "content-length": "926",
      "x-amzn-tls-version": "TLSv1.2",
      "x-forwarded-proto": "https",
      "x-forwarded-port": "443",
      "x-forwarded-for": "1.2.3.4",
      "accept": "*/*",
      "svix-id": "msg_asdf",
      "x-amzn-tls-cipher-suite": "ECDHE-RSA-AES128-GCM-SHA256",
      "svix-timestamp": "1707441209",
      "x-amzn-trace-id": "Root=1-asdf",
      "host": "asdf.lambda-url.us-west-2.on.aws",
      "content-type": "application/json",
      "user-agent": "Svix-Webhooks/1.17.0"
    },
    "requestContext": {
      "accountId": "anonymous",
      "apiId": "asdf",
      "domainName": "asdf.lambda-url.us-west-2.on.aws",
      "domainPrefix": "asdf",
      "http": {
        "method": "POST",
        "path": "/",
        "protocol": "HTTP/1.1",
        "sourceIp": "1.2.3.4",
        "userAgent": "Svix-Webhooks/1.17.0"
      },
      "requestId": "asdf",
      "routeKey": "$default",
      "stage": "$default",
      "time": "09/Feb/2024:01:13:30 +0000",
      "timeEpoch": 1707441210405
    },
    "body": "{\"data\":{\"birthday\":\"\",\"created_at\":1654012591514,\"email_addresses\":[{\"email_address\":\"example@example.org\",\"id\":\"idn_29w83yL7CwVlJXylYLxcslromF1\",\"linked_to\":[],\"object\":\"email_address\",\"reserved\":true,\"verification\":{\"attempts\":null,\"expire_at\":null,\"status\":\"verified\",\"strategy\":\"admin\"}}],\"external_accounts\":[],\"external_id\":null,\"first_name\":\"Example\",\"gender\":\"\",\"id\":\"user_29w83sxmDNGwOuEthce5gg56FcC\",\"image_url\":\"https://img.clerk.com/xxxxxx\",\"last_name\":null,\"last_sign_in_at\":null,\"object\":\"user\",\"password_enabled\":true,\"phone_numbers\":[],\"primary_email_address_id\":\"idn_29w83yL7CwVlJXylYLxcslromF1\",\"primary_phone_number_id\":null,\"primary_web3_wallet_id\":null,\"private_metadata\":{},\"profile_image_url\":\"https://www.gravatar.com/avatar?d=mp\",\"public_metadata\":{},\"two_factor_enabled\":false,\"unsafe_metadata\":{},\"updated_at\":1654012824306,\"username\":null,\"web3_wallets\":[]},\"object\":\"event\",\"type\":\"user.updated\"}",
    "isBase64Encoded": false
  },
  "parallelInvocation": true,
  "strategy": "cost",
  "stats": [
    {
      "averagePrice": 0,
      "averageDuration": 0,
      "totalCost": 0,
      "value": 128
    },
    {
      "averagePrice": 0,
      "averageDuration": 0,
      "totalCost": 0,
      "value": 256
    },
    {
      "averagePrice": 0,
      "averageDuration": 0,
      "totalCost": 0,
      "value": 512
    },
    {
      "averagePrice": 0,
      "averageDuration": 0,
      "totalCost": 0,
      "value": 1024
    },
    {
      "averagePrice": 0,
      "averageDuration": 0,
      "totalCost": 0,
      "value": 1536
    },
    {
      "averagePrice": 0,
      "averageDuration": 0,
      "totalCost": 0,
      "value": 2048
    },
    {
      "averagePrice": 0,
      "averageDuration": 0,
      "totalCost": 0,
      "value": 3008
    }
  ]
}

I pulled this interesting snippet of logs from the end of one of the executor logs:

2024-02-09T04:41:41.956Z	asdf	INFO	us-west-2 not found in base price map, using default: 2.1e-9
2024-02-09T04:41:41.958Z	asdf	INFO	Average duration:  0
2024-02-09T04:41:42.015Z	asdf	INFO	Stats:  { averagePrice: 0, averageDuration: 0, totalCost: 0, value: 1536 }

I can see all of the target lambda invocations ended successfully, so I’m not sure why this is happening. Any ideas?

About this issue

  • Original URL
  • State: closed
  • Created 5 months ago
  • Comments: 20 (11 by maintainers)

Commits related to this issue

Most upvoted comments

I’ve sucesfully testeed this fom 61acc54e0f4d23c4ad9d8ae8ed49cb5199afd3cf using manual SAM install and running it against same lambda with JSON logging enabled as before.

No issues with Unexpected end of JSON input or any other encountered. Given me the result as expected in execution output as well (was empty with that JSON issue). 👍

@ryancausey @MarcosDanielTorres-UALA @Malanius the fix has been merged to master. Could you please confirm that it runs without errors now? (it’s not deployed to SAR yet, you’ll need to fork & deploy “manually”).

Thank you all 🙏

We’re currently working on a fix!

FYI @Lavanya0513

Thanks for the quick turnaround! I optimized the lambda by switching it to text logs temporarily, but next time I run the optimizer I will double check.

@ryancausey this is now merged 😃

I haven’t published to SAR yet, but will do asap later this week (quite a few updates to document in the latest SAR version).

Let me know in case you encounter any issues or edge cases!