Skip to content

Conversation

lvthillo
Copy link

@lvthillo lvthillo commented Mar 17, 2025

Which issue(s) does this change fix?

Why is this change necessary?

I want to add the ability to override not only string values but also dictionary values in sam local generate-event. Currently, after running the CLI command, you have to manually adjust the file values.

An example is queryStringParameters in API Gateway. This is not supported via the CLI command. When making basic modifications to event-mapping.json and apigateway/AwsProxy.json to support the parameter, a string is returned, whereas queryStringParameters expects a dictionary.

That's why I'm making changes to generate_event to check if a value is of type dict. If so, the string value will be replaced with a dictionary.

I'm creating a draft PR to gather feedback and input on this feature and to see if it's considered a viable option (so I just added this for queryStringParams for API GW aws- proxy.

Test:

samdev local generate-event apigateway aws-proxy --method GET --path document --body "" --querystringparameters '{"documentId": "1044", "versionId": "v_1"}' --account-id '12345'

Output:

{
  "body": "",
  "resource": "/{proxy+}",
  "path": "/document",
  "httpMethod": "GET",
  "isBase64Encoded": true,
  "queryStringParameters": {
    "documentId": "1044",
    "versionId": "v_1"
  },
  "multiValueQueryStringParameters": {
    "foo": [
      "bar"
    ]
  },
  "pathParameters": {
    "proxy": "/document"
  },
  "stageVariables": {
    "baz": "qux"
  },
....
}

How does it address the issue?

What side effects does this change have?

Mandatory Checklist

PRs will only be reviewed after checklist is complete

  • Add input/output type hints to new functions/methods
  • Write design document if needed (Do I need to write a design document?)
  • Write/update unit tests
  • Write/update integration tests
  • Write/update functional tests if needed
  • make pr passes
  • make update-reproducible-reqs if dependencies were changed
  • Write documentation

By submitting this pull request, I confirm that my contribution is made under the terms of the Apache 2.0 license.

@github-actions github-actions bot added pr/external stage/needs-triage Automatically applied to new issues and PRs, indicating they haven't been looked at. labels Mar 17, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
pr/external stage/needs-triage Automatically applied to new issues and PRs, indicating they haven't been looked at.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants