jkakar / aws-codegen

Code generator for AWS clients in Elixir.
Other
35 stars 0 forks source link

Amazon SNS #28

Open electic opened 8 years ago

electic commented 8 years ago

Great library. Any plans to support SNS?

jkakar commented 8 years ago

Thanks @electic! Yes, it's on my todo list, I just haven't managed to find time to get there. SNS uses the query protocol which involves converting XML from the service to Erlang and Elixir maps, and vice versa, which is a bit tricky. I'll get there eventually, but can't promise when right now.

electic commented 8 years ago

No problem. Thank you!

brentonannan commented 8 years ago

... I completely missed this issue before doing my PRs. Apologies if I've wasted time, @jkakar.

jkakar commented 8 years ago

@brentonannan Not a waste at all, please ask questions whenever they come up, I'm happy to try and help if I can! I'm not expecting to get to this issue anytime in the next few weeks, so if you have energy to put here, I'd welcome contributions. The same kind of issue that exists for SNS also exists for SQS and there's some discussion about that in jkakar/aws-elixir#27. Basically, we need to figure out how to convert from XML to map and back again. My current thinking is to implement that logic in aws-erlang and then re-use it in aws-elixir.

electic commented 8 years ago

It would be great to have a solution. I ended up using erlcloud and doing something like this:

` token = token_arn |> String.to_char_list msg = message |> String.to_char_list

    :erlcloud_sns.configure(access_key, secret, endpoint)
    :erlcloud_sns.publish_to_target(token, msg)`

But would love for this to be in Elixir. I would write it myself and PR it but I just started off in Elixir and frankly, I am really bad at it so far.

slashmili commented 8 years ago

Is the same reason that there is no S3 module?

jkakar commented 8 years ago

@slashmili Yes, exactly.

dstendardi commented 7 years ago

@jkakar I might find some time to work on query protocol support. Do you mind if I open a dedicated issue about this and close this one ?

ghost commented 7 years ago

@dstendardi and @jkakar I'd be interesting in working on this as well if I can be of any help.

jkakar commented 7 years ago

@dstendardi Closing this one and opening a dedicated issue sounds great, thanks!

dstendardi commented 7 years ago

@kingoftheknoll I think there is enough work for both. I see mainly two parts (serializing the query, and deserialize the response). I'll open an issue and start working on it during this week.

ghost commented 7 years ago

Agreed. I spent some time last night looking at the XML format and it looks like it should be possible to build up the full DOM tree described by the spec and then collapse it into xpath selectors and use sweetXML. About a month ago I started playing around with using SweetXML for use with ex_aws because it also doesn't deserialize the response.

Result looks like this:

  import SweetXml

  def xml_to_map(xml) do
    xml |> xpath(~x"//instancesSet"l,
      instance_id: ~x".//instanceId/text()"s,
      image_id: ~x".//imageId/text()"s,
      state: ~x".//instanceState/name/text()"s,
      private_dns_name: ~x"./item/privateDnsName/text()"s,
      dns_name: ~x".//dnsName/text()"s,
      key_name: ~x".//keyName/text()"s,
      instance_type: ~x".//instanceType/text()"s,
      launch_time: ~x".//launchTime/text()"s,
      availability_zone: ~x".//placement/availabilityZone/text()"s,
      subnet_id: ~x"./item/subnetId/text()"s,
      vpc_id: ~x"./item/vpcId/text()"s,
      private_ip_address: ~x"./item/privateIpAddress/text()"s,
      public_ip_address: ~x"./item/ipAddress/text()"s,
      access_lists: [
        ~x"./item/groupSet"l,
        access_list_id: ~x".//groupId/text()"s,
        access_list_name: ~x".//groupName/text()"s
      ]
    )
  end

Granted here I'm only doing the InstanceSet rather than the whole reservationSet but you get the idea. Because AWS doesn't use attributes in the xml elements this makes everything much easier. So it should be possible to have a very clear one-to-one bi-directional translation between a Map and the XML. I think I good first step would be a take the DescribeInstancesResponse schema and a test response and test that in isolation since I'm not too familiar with the code gen repo.