如何在AWS API Gateway中的Body Mapping模板中定义URL查询参数?

时间:2017-04-11 08:37:01

标签: amazon-web-services aws-api-gateway

我的api形式如下:

override func viewDidLoad() {
        super.viewDidLoad()
        initialLabelCenter = labelSliderValue.center.x
    }

    //Set value of slider into label from 100 to 1000
    @IBAction func sliderActionValueChanged(_ sender: UISlider) {
        let currentValue: CGFloat = CGFloat(sender.value)
        labelSliderValue.text = String(describing: currentValue)

        //Returns the drawing rectangle for the slider’s track
        let trackRect = sliderInstance.trackRect(forBounds: sliderInstance.bounds)

        //Returns the drawing rectangle for the slider’s thumb image.
        let sliderThumbRect = sliderInstance.thumbRect(forBounds: sliderInstance.bounds, trackRect: trackRect, value: sliderInstance.value)

        //Set label's center to move in a particular direction. In this case it will move left to right horizontally
        labelSliderValue.center = CGPoint(x: initialLabelCenter + sliderThumbRect.origin.x, y: self.labelSliderValue.center.y)
    }

目前,我刚刚在我的映射模板中定义了https://<>.execute-api.us-east-1.amazonaws.com/Testing/api/v1/mobs/<>.json?filename=<>.json&assertion=1 ,如下所示:

.../mobs/<>.json

现在,我在网址中添加了{ "mob_type": "$input.params('type')" } filename的查询参数。那么,我如何在Body Mapping Template中定义它们呢?

这不起作用:

assertion

1 个答案:

答案 0 :(得分:2)

在“URL查询字符串参数”下的“集成请求”中,您需要添加

的映射
  • method.request.querystring.type
  • method.request.querystring.filename
  • method.request.querystring.assertion

http://docs.aws.amazon.com/apigateway/latest/developerguide/request-response-data-mappings.html#mapping-request-parameters

通过映射,可以在Body Mapping Templates中访问它们。