Skip to content

ApiGatewayCustomAuthorizerResponse unable to deserialize example #853

@aesterline

Description

@aesterline

When deserializing the authorizer response described in APIGateway example lambda authorizer output I get the following error:

called `Result::unwrap()` on an `Err` value: Error("invalid type: string \"execute-api:Invoke\", expected a sequence", line: 0, column: 0)

Example Test

#[cfg(test)]
mod tests {
    use aws_lambda_events::apigw::ApiGatewayCustomAuthorizerResponse;
    use serde_json::json;

    #[test]
    fn can_parse_aws_example() {
        let example = json!({
          "principalId": "myid",
          "policyDocument": {
            "Version": "2012-10-17",
            "Statement": [
              {
                "Action": "execute-api:Invoke",
                "Effect": "Allow",
                "Resource": "arn:aws:execute-api:us-east-2:128298128:kaidfa/prod/GET/foo/bar"
              }
            ]
          },
          "context": {
            "stringKey": "value",
            "numberKey": "1",
            "booleanKey": "true"
          },
          "usageIdentifierKey": "apikey"
        });

        let parsed: ApiGatewayCustomAuthorizerResponse = serde_json::from_value(example).unwrap();
        assert_eq!(
            parsed.policy_document.statement[0].action[0],
            "execute-api:Invoke"
        );
    }
}

The examples in https://docs.aws.amazon.com/apigateway/latest/developerguide/api-gateway-control-access-using-iam-policies-to-invoke-api.html#api-gateway-calling-api-permissions seems to show Action as a Vec<String>. I'm not sure which version is correct or if we should be able to deserialize both variants. I do have a custom authorizer I am trying to integrate with currently that returns the single String variant. Is it possible to change the current serde definition to allow parsing both versions?

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions