I encountered an issue when calling the API of cloudfront. I called a POST API and got a 400 http error code. I print the log of request body in the execute.lua:
<?xml version="1.0" encoding="UTF-8"?>
<input>
<ResponseHeadersPolicyConfig xmlns="http://cloudfront.amazonaws.com/doc/2020-05-31/">
<Name>cdn_test</Name>
<CorsConfig>
<AccessControlAllowMethods>
<Items>
<Method>GET</Method>
<Method>POST</Method>
</Items>
<Quantity>2</Quantity>
</AccessControlAllowMethods>
<AccessControlAllowCredentials>false</AccessControlAllowCredentials>
<AccessControlMaxAgeSec>600</AccessControlMaxAgeSec>
<AccessControlAllowHeaders>
<Items>
<Header>*</Header>
</Items>
<Quantity>1</Quantity>
</AccessControlAllowHeaders>
<OriginOverride>true</OriginOverride>
<AccessControlAllowOrigins>
<Items>
<Origin>*</Origin>
</Items>
<Quantity>1</Quantity>
</AccessControlAllowOrigins>
</CorsConfig>
<CustomHeadersConfig>
<Items>
<ResponseHeadersPolicyCustomHeader>
<Override>true</Override>
<Value>rcy</Value>
<Header>name</Header>
</ResponseHeadersPolicyCustomHeader>
</Items>
<Quantity>1</Quantity>
</CustomHeadersConfig>
</ResponseHeadersPolicyConfig>
</input>
And the response body returned by AWS server:
<?xml version="1.0"?>
<ErrorResponse xmlns="http://cloudfront.amazonaws.com/doc/2020-05-31/">
<Error>
<Type>Sender</Type>
<Code>MalformedInput</Code>
<Message>input is not valid, expected ResponseHeadersPolicyConfig</Message>
</Error>
<RequestId>cd10f090-22eb-41b3-94df-4264f9d45402</RequestId>
</ErrorResponse>
Then I checked the AWS REST API document, just found that request body shouldn't have the root input tag.
The input tag come from the raw-api api-description files. After I changed the code to remove the input tag, the call succeed.
build.lua#232
-- encode rest of the body data here
-- poor_mans_xml_encoding(xml_data, operation.input, "input", body_tbl)
for name, member in pairs(operation.input.members) do
if body_tbl[name] then
poor_mans_xml_encoding(xml_data, member, name, body_tbl[name], 0)
end
end
But I'm not sure if I missed something else.
I encountered an issue when calling the API of cloudfront. I called a POST API and got a 400 http error code. I print the log of request body in the execute.lua:
And the response body returned by AWS server:
Then I checked the AWS REST API document, just found that request body shouldn't have the root
inputtag.The
inputtag come from the raw-api api-description files. After I changed the code to remove the input tag, the call succeed.But I'm not sure if I missed something else.