Coder Social home page Coder Social logo

Add support for EC2 about aws-elixir HOT 4 CLOSED

aws-beam avatar aws-beam commented on August 18, 2024 5
Add support for EC2

from aws-elixir.

Comments (4)

dynnamitt avatar dynnamitt commented on August 18, 2024 2

Just curious (and I know it's more layers) but did you try https://hexdocs.pm/aws/AWS.AutoScaling.html
I also wish the ec2 api would be support tho

from aws-elixir.

philipgiuliani avatar philipgiuliani commented on August 18, 2024

In the meanwhile I am using this to get my required API call.

defmodule AWS.EC2 do
  def describe_network_interfaces(client, input, options \\ []) do
    request(client, "DescribeNetworkInterfaces", input, options)
  end

  @spec request(AWS.Client.t(), binary(), map(), list()) ::
          {:ok, Poison.Parser.t() | nil, Poison.Response.t()}
          | {:error, Poison.Parser.t()}
          | {:error, HTTPoison.Error.t()}
  defp request(client, action, input, options) do
    client = %{client | service: "ec2"}
    host = build_host("ec2", client)
    url = build_url(host, client)

    headers = [
      {"Host", host},
      {"Content-Type", "application/x-www-form-urlencoded"}
    ]

    input = Map.merge(input, %{"Action" => action, "Version" => "2016-11-15"})
    payload = AWS.Util.encode_query(input)
    headers = AWS.Request.sign_v4(client, "POST", url, headers, payload)

    case HTTPoison.post(url, payload, headers, options) do
      {:ok, %HTTPoison.Response{status_code: 200, body: ""} = response} ->
        {:ok, nil, response}

      {:ok, %HTTPoison.Response{status_code: 200, body: body} = response} ->
        {:ok, AWS.Util.decode_xml(body), response}

      {:ok, %HTTPoison.Response{body: body}} ->
        error = AWS.Util.decode_xml(body)
        {:error, error}

      {:error, %HTTPoison.Error{reason: reason}} ->
        {:error, %HTTPoison.Error{reason: reason}}
    end
  end

  defp build_host(_endpoint_prefix, %{region: "local"}) do
    "localhost"
  end

  defp build_host(endpoint_prefix, %{region: region, endpoint: endpoint}) do
    "#{endpoint_prefix}.#{region}.#{endpoint}"
  end

  defp build_url(host, %{:proto => proto, :port => port}) do
    "#{proto}://#{host}:#{port}/"
  end
end

from aws-elixir.

ruslandoga avatar ruslandoga commented on August 18, 2024
defmodule AWS.EC2 do
  alias AWS.Request

  def metadata do
    %AWS.ServiceMetadata{
      api_version: "2016-11-15",
      content_type: "text/xml",
      endpoint_prefix: "ec2",
      global?: false,
      protocol: "query",
      signing_name: "ec2"
    }
  end

  def describe_instances(client, input, options \\ []) do
    Request.request_post(client, metadata(), "DescribeInstances", input, options)
  end
end

seems to work for me:

> iex
Erlang/OTP 25 [RELEASE CANDIDATE 2] [erts-13.0] [source] [64-bit] [smp:8:8] [ds:8:8:10] [async-threads:1] [jit]

Interactive Elixir (1.14.0-dev) - press Ctrl+C to exit (type h() ENTER for help)

iex(1)> Mix.install [:aws, :jason, :hackney]
iex(2)> defmodule AWS.EC2 do
...(2)>   alias AWS.Request
...(2)>
...(2)>   def metadata do
...(2)>     %AWS.ServiceMetadata{
...(2)>       api_version: "2016-11-15",
...(2)>       content_type: "text/xml",
...(2)>       endpoint_prefix: "ec2",
...(2)>       global?: false,
...(2)>       protocol: "query",
...(2)>       signing_name: "ec2"
...(2)>     }
...(2)>   end
...(2)>
...(2)>   def describe_instances(client, input, options \\ []) do
...(2)>     Request.request_post(client, metadata(), "DescribeInstances", input, options)
...(2)>   end
...(2)> end

iex(3)> client = AWS.Client.create("eu-north-1")
iex(4)> AWS.EC2.describe_instances(client, _input = %{})
{:ok,
 %{
   "DescribeInstancesResponse" => %{
     "requestId" => "57587f0e-31f9-4d70-8f27-87b738f39f2b",
     "reservationSet" => %{
       "item" => [
         %{
           "groupSet" => :none,
           "instancesSet" => %{
             "item" => %{
               "tagSet" => %{
               # ...

from aws-elixir.

cheese-head avatar cheese-head commented on August 18, 2024

I've created two pull requests that would add support for ec2.
aws-beam/aws-codegen#100
#170

from aws-elixir.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.