aws-codegen icon indicating copy to clipboard operation
aws-codegen copied to clipboard

Amazon SNS

Open electic opened this issue 8 years ago • 12 comments

Great library. Any plans to support SNS?

electic avatar Mar 26 '16 06:03 electic

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.

jkakar avatar Mar 26 '16 07:03 jkakar

No problem. Thank you!

electic avatar Mar 26 '16 07:03 electic

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

brentonannan avatar Apr 12 '16 01:04 brentonannan

@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.

jkakar avatar Apr 12 '16 02:04 jkakar

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.

electic avatar Apr 12 '16 02:04 electic

Is the same reason that there is no S3 module?

slashmili avatar Aug 25 '16 14:08 slashmili

@slashmili Yes, exactly.

jkakar avatar Aug 25 '16 14:08 jkakar

@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 ?

dstendardi avatar Mar 05 '17 15:03 dstendardi

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

ghost avatar Mar 07 '17 04:03 ghost

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

jkakar avatar Mar 07 '17 05:03 jkakar

@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.

dstendardi avatar Mar 07 '17 15:03 dstendardi

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.

ghost avatar Mar 07 '17 16:03 ghost