Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Feat allow dict values in generate event cmd #7938

Draft
wants to merge 2 commits into
base: develop
Choose a base branch
from

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.

1 participant