AWSCore.jl

AWSCore.jl Documentation

Amazon Web Services Core Functions and Types.

https://github.com/JuliaCloud/AWSCore.jl

AWSCore Configuration

Most AWSCore functions take a AWSConfig dictionary as the first argument. This dictionary holds AWSCredentials and AWS region configuration.

aws = AWSConfig(:creds => AWSCredentials(), :region => "us-east-1")`
AWSCore.aws_configFunction.

The aws_config function provides a simple way to creates an AWSConfig configuration dictionary.

>aws = aws_config()
>aws = aws_config(creds = my_credentials)
>aws = aws_config(region = "ap-southeast-2")

By default, the aws_config attempts to load AWS credentials from:

A ~/.aws/credentials file can be created using the AWS CLI command aws configrue. Or it can be created manually:

[default]
aws_access_key_id = AKIAXXXXXXXXXXXXXXXX
aws_secret_access_key = XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX

If your ~/.aws/credentials file contains multiple profiles you can select a profile by setting the AWS_PROFILE environment variable.

aws_config understands the following AWS CLI environment variables: AWS_ACCESS_KEY_ID, AWS_SECRET_ACCESS_KEY, AWS_SESSION_TOKEN, AWS_DEFAULT_REGION, AWS_PROFILE and AWS_CONFIG_FILE.

An configuration dictionary can also be created directly from a key pair as follows. However, putting access credentials in source code is discouraged.

aws = aws_config(creds = AWSCredentials("AKIAXXXXXXXXXXXXXXXX",
                                        "XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX"))

default_aws_config returns a global shared AWSConfig object obtained by calling aws_config with no optional arguments.

AWSCore.aws_user_arnFunction.
aws_user_arn(::AWSConfig)

Unique Amazon Resource Name for configrued user.

e.g. "arn:aws:iam::account-ID-without-hyphens:user/Bob"

aws_account_number(::AWSConfig)

12-digit AWS Account Number.

AWSCore Internals

AWS Security Credentials

When you interact with AWS, you specify your AWS Security Credentials to verify who you are and whether you have permission to access the resources that you are requesting. AWS uses the security credentials to authenticate and authorize your requests.

The fields access_key_id and secret_key hold the access keys used to authenticate API requests (see Creating, Modifying, and Viewing Access Keys).

Temporary Security Credentials require the extra session token field.

The user_arn and account_number fields are used to cache the result of the aws_user_arn and aws_account_number functions.

The AWSCredentials() constructor tries to load local Credentials from environment variables, ~/.aws/credentials or EC2 instance credentials.

Load Credentials from environment variables AWS_ACCESS_KEY_ID, AWS_SECRET_ACCESS_KEY etc. (e.g. in Lambda sandbox).

Load Credentials from AWS CLI ~/.aws/credentials file.

Load Instance Profile Credentials for EC2 virtual machine.

Endpoints and Resource Names

AWSCore.aws_endpointFunction.
aws_endpoint(service, [region, [hostname_prefix]])

Generate service endpoint URL for service and region.

AWSCore.aws_endpoint("sqs", "eu-west-1")
"http://sqs.eu-west-1.amazonaws.com"
AWSCore.arnFunction.
arn([::AWSConfig], service, resource, [region, [account]])

Generate an Amazon Resource Name for service and resource.

AWSCore.arn("sqs", "au-test-queue", "ap-southeast-2", "1234")
"arn:aws:sqs:ap-southeast-2:1234:au-test-queue"
AWSCore.arn(default_aws_config(), "sns", "au-test-topic")
"arn:aws:sns:ap-southeast-2:551613799374:au-test-topic"
AWSCore.arn_regionFunction.
arn_region(arn)

Extract region name from arn.

API Requests

AWSRequest
do_request
dump_aws_request
post_request
post_request(aws_config(), "sdb", "2009-04-15", Dict("Action" => "ListDomains"))

Execution Environemnt

Is Julia running in an AWS Lambda sandbox?

Is Julia running on an EC2 virtual machine?

AWSCore.ec2_metadataFunction.
ec2_metadata(key)

Fetch EC2 meta-data for key.

Utility Functions

mime_multipart([header,] parts)

Encode parts as a MIME Multipart message.

parts is a Vector of (filename, content_type, content) Tuples.

println(AWSCore.mime_multipart([
     ("foo.txt", "text/plain", "foo"),
     ("bar.txt", "text/plain", "bar")
 ]))
MIME-Version: 1.0
Content-Type: multipart/mixed; boundary="=PRZLn8Nm1I82df0Dtj4ZvJi="


--=PRZLn8Nm1I82df0Dtj4ZvJi=
Content-Type: text/plain;
    name=foo.txt
Content-Disposition: attachment;
    filename=foo.txt
Content-Transfer-Encoding: binary

foo
--=PRZLn8Nm1I82df0Dtj4ZvJi=
Content-Type: text/plain;
    name=bar.txt
Content-Disposition: attachment;
    filename=bar.txt
Content-Transfer-Encoding: binary

bar
--=PRZLn8Nm1I82df0Dtj4ZvJi=--