0

AWS API gateway requires request template of type application/json, as shown above, AWS Gateway will parse and pass these values to AWS lambda. This should be created by python boto3. Structure is something similar to JSON structure in Java script

{
"userName":$input.json('$.userName'),
"password":$input.json('$.password'),
}
5
  • The python equivalent is called dictionary. Commented Apr 22, 2020 at 9:01
  • But in python we can't build a dictionary to have a value $input.json, it should be a string or bool or any other object Commented Apr 22, 2020 at 9:02
  • Is $input.json jQuery syntax? Commented Apr 22, 2020 at 9:07
  • Yes, this will be used in AWS API gateway request template which is of type application/json and this needs to be created through python Commented Apr 22, 2020 at 9:09
  • How are you supposed to pass user name and password? It's not really clear what the use case is. Commented Apr 22, 2020 at 9:14

1 Answer 1

1

You can use the json module to create JSON from internal python structures:

import json

data = {'username': '....', 'password': '....'}
print(json.dumps(data))

If you don't need to export it as a JSON structure, you can use the dictionary directly:

data = {'username': '....', 'password': '....'}
print(data['username'])
Sign up to request clarification or add additional context in comments.

4 Comments

Value should not be enclosed with quotes as detailed in my question
They'll have to be, unless they're references to variables. If you have variables defined, then you can refer them directly. If you have a different need, you'll have to clarify that in your question.
Actually in AWS API gateway we need to add request template, as shown above, API Gateway will parse and pass these values to AWS lambda, this request template should be of application/json and should be created by python boto3
I think you're going to have to build that manually in that case, by iterating over the dictionary and output a JSON-like structure for each variable reference. Add these details to your question - it's impossible to tell that this is what you want from the question.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.