erlcloud

适用于 Erlang 的 AWS API 库(Amazon EC2,S3,SQS,DDB,ELB等)。【 AWS APIs library for Erlang (Amazon EC2, S3, SQS, DDB, ELB and etc) 】

  • Owner: erlcloud/erlcloud
  • Platform: Linux, Mac, Windows
  • License:: Other
  • Category::
  • Topic:
  • Like:
    0
      Compare:

Github stars Tracking Chart

erlcloud:适用于Erlang 的 AWS API 库

此库不是由 AWS 开发或维护的, 因此与所有的 aws-cli boto 相比, 仍然缺少大量的功能。根据要求添加所需的功能。

实施的服务API:

  • Amazon Elastic Compute Cloud(EC2)
  • Amazon EC2容器服务(ECS)
  • Amazon Simple Storage Service(S3)
  • 亚马逊简单队列服务(SQS)
  • Amazon SimpleDB
  • Amazon Mechanical Turk
  • Amazon CloudWatch(MON)
  • Amazon CloudSearch
  • Amazon Inspector
  • 亚马逊密钥管理服务(KMS)
  • Amazon DirectConnect
  • Amazon DynamoDB& DDB流(ddb2)
  • Amazon Autoscaling(AS)
  • Amazon CloudTrail(CT)
  • Cloud Formation(CFN)
  • ElasticLoadBalancing(ELB)
  • 身份和访问管理(IAM)
  • 室壁运动
  • 胶水(目录表,抓取工具和作业API支持)
  • 雅典娜
  • CloudWatch的
  • MechanicalTurk
  • 简单数据库(SDB)
  • 关系数据服务(RDS)
  • 简单电子邮件服务(SES)
  • 短令牌服务(STS)
  • 简易通知服务(SNS)
  • Web应用程序防火墙(WAF)
  • 以及更多来

大部分API函数已经实现。 并非所有功能都经过全面测试,因此在将此库集成到生产代码时应特别小心。 请发送问题和补丁。

这些库可以使用两种方式:

  • 您可以在流程字典中指定配置参数。对简单任务很有用
  • 您可以创建一个配置对象,并将其作为最终参数传递给每个请求。对跨AWS账户访问有用

路线图

以下是该库的路线图更新以及常规功能和修补程序。

  • 3.0.x的
    • 删除R16支持 完成
    • 支持地图
  • 3.X.X
    • 修复透析器检查结果并将其强制存入库
    • 只有 SigV4 签名并在一个模块中推广。仅在 SBD 部分保留 SigV2
    • 不再有

主要API兼容性在0.13.X和2.0.x之间变化

  • ELB API
  • ...即将填写名单

支持的Erlang版本

目前我们支持以下OTP版本:

  • 17.5
  • 18.1
  • 19.1
  • 20.0

开始

您需要克隆存储库并下载钢筋/rebar3(如果它不在您的路径中)。

git clone https://github.com/erlcloud/erlcloud.git
cd erlcloud
wget https://s3.amazonaws.com/rebar3/rebar3
chmod a+x rebar3

编译并运行erlcloud

make
make run

如果您在应用程序中使用erlcloud,请将其作为应用程序配置文件中的依赖项添加。 要在shell中使用erlcloud,可以通过调用以下命令启动它:

application:ensure_all_started(erlcloud).

使用临时安全证书

访问AWS资源可能通过第三方身份提供商。 使用 临时安全证书管理访问。

您可以在OS环境变量中提供您的亚马逊凭证

export AWS_ACCESS_KEY_ID=<Your AWS Access Key>
export AWS_SECRET_ACCESS_KEY=<Your AWS Secret Access Key>
export AWS_SESSION_TOKEN=<Your AWS Security Token>
export AWS_DEFAULT_REGION=<Your region>

如果您没有在操作系统环境变量中提供您的亚马逊凭据,那么您需要提供从您的配置文件读取配置:

{ok, Conf} = erlcloud_aws:profile().
erlcloud_s3:list_buckets(Conf).

或者您可以通过 erlcloud 应用程序环境变量提供它们。

application:set_env(erlcloud, aws_access_key_id, "your key"),
application:set_env(erlcloud, aws_secret_access_key, "your secret key"),
application:set_env(erlcloud, aws_security_token, "your token"),
application:set_env(erlcloud, aws_region, "your region"),

使用访问密钥

您可以在环境变量中提供您的亚马逊凭证。

export AWS_ACCESS_KEY_ID=<Your AWS Access Key>
export AWS_SECRET_ACCESS_KEY=<Your AWS Secret Access Key>

如果您没有在环境变量中提供您的亚马逊凭据,那么您需要提供每个进程的配置:

erlcloud_ec2:configure(AccessKeyId, SecretAccessKey [, Hostname]).

主机名默认为不存在的“ec2.amazonaws.com”故意避免与US-East-1混合 有关所有服务配置的完整说明,请参阅 aws_config

配置对象的用法:

EC2 = erlcloud_ec2:new(AccessKeyId, SecretAccessKey [, Hostname])
erlcloud_ec2:describe_images(EC2).

aws_config

aws_config记录包含许多有价值的默认值,例如AWS服务的协议和端口。 您始终可以通过创建新的#aws_config {}记录并更改特定字段,然后将结果传递给任何erlcloud函数来重新定义它们。 但是如果你想在运行时改变一些东西,这可能是乏味的和/或不够灵活。

另一种方法是在 app.config -> erlcloud -> aws_config 部分中设置默认字段,并依赖默认情况下所有函数使用的配置。

这样的app.config示例:

[
  {erlcloud, [
      {aws_config, [
          {s3_scheme, "http://"},
          {s3_host, "s3.example.com"}
      ]}
  ]}
].

基本使用

然后你就可以开始进行api调用了,如:

erlcloud_ec2:describe_images().
% list buckets of Account stored in config in process dict
% of of the account you are running in.
erlcloud_s3:list_buckets().
erlcloud_s3:list_buckets(erlcloud_aws:default_cfg()).
% List buckets on 3d Account from Conf
erlcloud_s3:list_buckets(Conf).

创建EC2实例可能如下所示:

start_instance(Ami, KeyPair, UserData, Type, Zone) ->
    Config = #aws_config{
            access_key_id = application:get_env(aws_key),
            secret_access_key = application:get_env(aws_secret)
           },
    InstanceSpec = #ec2_instance_spec{image_id = Ami,
                                      key_name = KeyPair,
                                      instance_type = Type,
                                      availability_zone = Zone,
                                      user_data = UserData},
    erlcloud_ec2:run_instances(InstanceSpec, Config).

有关使用信息,请查阅源代码和 https://hexdocs.pm/erlcloud 。 有关详细的API描述,请参阅以下位置的AWS参考资料:

备注

缩进的贡献应该遵循缩进式的周围文本。 一般来说,它遵循由OTP团队提供的官方erlang模式的默认缩进规则。

最佳实践

  • 所有接口都应提供使用非默认配置的方法。
  • 具有分页逻辑的公共接口应该在某些模块中找到的 {{paged,Marker},Results} 更喜欢 {ok,Results,Marker} 样式。 在记录输出的情况下,令牌应该是记录的一部分。
  • 传递下一页 NextToken 时, NextMarker 优先于 Opts ,而不是许多模块中的有趣参数。
  • 公共接口通常应该将proplists暴露在记录之上。所有新模块都有优先考虑。
  • 暴露的记录只能用于复杂的输出。示例如下:ddb2,ecs。
  • 库不应该公开任何长时间运行或有状态的进程 - 没有gen_servers,没有缓存等。

Overview

Name With Ownererlcloud/erlcloud
Primary LanguageErlang
Program languageMakefile (Language Count: 3)
PlatformLinux, Mac, Windows
License:Other
Release Count152
Last Release Name3.7.6 (Posted on 2024-03-05 14:59:08)
First Release Namev0.8.0 (Posted on )
Created At2010-10-14 20:32:41
Pushed At2024-04-09 09:47:29
Last Commit At2024-03-05 10:58:07
Stargazers Count650
Watchers Count46
Fork Count438
Commits Count2k
Has Issues Enabled
Issues Count196
Issue Open Count23
Pull Requests Count490
Pull Requests Open Count9
Pull Requests Close Count73
Has Wiki Enabled
Is Archived
Is Fork
Is Locked
Is Mirror
Is Private

erlcloud: AWS APIs library for Erlang

Build Status

This library is not developed or maintained by AWS thus lots of functionality is still missing comparing to aws-cli or boto.
Required functionality is being added upon request.

Service APIs implemented:

  • Amazon Elastic Compute Cloud (EC2)
  • Amazon EC2 Container Service (ECS)
  • Amazon Simple Storage Service (S3)
  • Amazon Simple Queue Service (SQS)
  • Amazon SimpleDB
  • Amazon Mechanical Turk
  • Amazon CloudWatch (MON)
  • Amazon CloudSearch
  • Amazon Inspector
  • Amazon Key Management Service (KMS)
  • Amazon DirectConnect
  • Amazon DynamoDB & DDB streams (ddb2)
  • Amazon Autoscaling (AS)
  • Amazon CloudTrail (CT)
  • Cloud Formation (CFN)
  • Config
  • ElasticLoadBalancing (ELB)
  • Identity and Access Management (IAM)
  • Kinesis
  • Glue (Catalog table, Crawlers and Job APIs support)
  • Athena
  • Step Functions (SF)
  • CloudWatch
  • MechanicalTurk
  • Simple DB (SDB)
  • Relational Data Service (RDS)
  • Simple Email Service (SES)
  • Short Token Service (STS)
  • Simple Notification Service (SNS)
  • Web Application Firewall (WAF)
  • AWS Cost and Usage Report API
  • and more to come

Majority of API functions have been implemented.
Not all functions have been thoroughly tested, so exercise care when integrating this library into production code.
Please send issues and patches.

The libraries can be used two ways:

  • either you can specify configuration parameters in the process dictionary. Useful for simple tasks
  • you can create a configuration object and pass that to each request as the final parameter. Useful for Cross AWS Account access

Roadmap

Below is the library roadmap update along with regular features and fixes.

  • 3.0.X

    • Remove R16 support done
    • Support maps
  • 3.X.X

    • Fix dialyzer findings and make it mandatory for the library
    • Only SigV4 signing and generalised in one module. Keep SigV2 in SBD section only
    • No more erlang:error() use and use of regular tuples as error API. Breaking change.

Major API compatibility changes between 0.13.X and 2.0.x

  • ELB APIs
  • ... list to be filled shortly

Supported Erlang versions

At the moment we support the following OTP releases:

  • 19.3
  • 20.3
  • 21.1

it might still work on 17+ (primariliy due to Erlang maps) but we do not guarantee that.

Getting started

You need to clone the repository and download rebar/rebar3 (if it's not already available in your path).

git clone https://github.com/erlcloud/erlcloud.git
cd erlcloud
wget https://s3.amazonaws.com/rebar3/rebar3
chmod a+x rebar3

To compile and run erlcloud

make
make run

If you're using erlcloud in your application, add it as a dependency in your application's configuration file.
To use erlcloud in the shell, you can start it by calling:

application:ensure_all_started(erlcloud).

Using Temporary Security Credentials

The access to AWS resource might be managed through third-party identity provider.
The access is managed using temporary security credentials.

You can provide your amazon credentials in OS environmental variables

export AWS_ACCESS_KEY_ID=<Your AWS Access Key>
export AWS_SECRET_ACCESS_KEY=<Your AWS Secret Access Key>
export AWS_SESSION_TOKEN=<Your AWS Security Token>
export AWS_DEFAULT_REGION=<Your region>

If you did not provide your amazon credentials in the OS environmental variables, then you need to provide configuration read from your profile:

{ok, Conf} = erlcloud_aws:profile().
erlcloud_s3:list_buckets(Conf).

Or you can provide them via erlcloud application environment variables.

application:set_env(erlcloud, aws_access_key_id, "your key"),
application:set_env(erlcloud, aws_secret_access_key, "your secret key"),
application:set_env(erlcloud, aws_security_token, "your token"),
application:set_env(erlcloud, aws_region, "your region"),

Using Access Key

You can provide your amazon credentials in environmental variables.

export AWS_ACCESS_KEY_ID=<Your AWS Access Key>
export AWS_SECRET_ACCESS_KEY=<Your AWS Secret Access Key>

If you did not provide your amazon credentials in the environmental variables, then you need to provide the per-process configuration:

erlcloud_ec2:configure(AccessKeyId, SecretAccessKey [, Hostname]).

Hostname defaults to non-existing "ec2.amazonaws.com" intentionally to avoid mix with US-East-1
Refer to aws_config for full description of all services configuration.

Configuration object usage:

EC2 = erlcloud_ec2:new(AccessKeyId, SecretAccessKey [, Hostname])
erlcloud_ec2:describe_images(EC2).

aws_config

aws_config record contains many valuable defaults,
such as protocols and ports for AWS services. You can always redefine them by making new #aws_config{} record and
changing particular fields, then passing the result to any erlcloud function.
But if you want to change something in runtime this might be tedious and/or not flexible enough.

Alternative approach is to set default fields within the app.config -> erlcloud -> aws_config section and
rely on the config, used by all functions by default.

Example of such app.config:

[
  {erlcloud, [
      {aws_config, [
          {s3_scheme, "http://"},
          {s3_host, "s3.example.com"}
      ]}
  ]}
].

Basic use

Then you can start making api calls, like:

erlcloud_ec2:describe_images().
% list buckets of Account stored in config in process dict
% of of the account you are running in.
erlcloud_s3:list_buckets().
erlcloud_s3:list_buckets(erlcloud_aws:default_cfg()).
% List buckets on 3d Account from Conf
erlcloud_s3:list_buckets(Conf).

Creating an EC2 instance may look like this:

start_instance(Ami, KeyPair, UserData, Type, Zone) ->
    Config = #aws_config{
            access_key_id = application:get_env(aws_key),
            secret_access_key = application:get_env(aws_secret)
           },

    InstanceSpec = #ec2_instance_spec{image_id = Ami,
                                      key_name = KeyPair,
                                      instance_type = Type,
                                      availability_zone = Zone,
                                      user_data = UserData},
    erlcloud_ec2:run_instances(InstanceSpec, Config).

For usage information, consult the source code and https://hexdocs.pm/erlcloud.
For detailed API description refer to the AWS references at:

Notes

Indentation in contributions should follow indentation style of surrounding text.
In general it follows default indentation rules of official erlang-mode as provided by OTP team.

Best Practices

  • All interfaces should provide a method for working with non-default config.
  • Public interfaces with paging logic should prefer {ok, Results, Marker} style to the {{paged, Marker}, Results} found in some modules.
    In case of records output, tokens should be part of the record.
  • Passing next page NextToken, NextMarker is preferred with Opts rather than a fun parameter like found in many modules.
  • Public interfaces should normally expose proplists over records. All new modules are preferred to have both.
  • Exposed records are to be used only for complex outputs. Examples to follow: ddb2, ecs.
  • Library should not expose any long running or stateful processes - no gen_servers, no caches and etc.
To the top