2 All Services
2.1 Names
The names of procedures and structs generally do not have special prefixes. Use the prefix-in option for require if you prefer a prefix (or need one to avoid a name collision).
For example if you want the aws/sns procedures to have an sns- prefix, so that create-topic is renamed to sns-create-topic:
(require (prefix-in sns- aws/sns)) (sns-create-topic "foobar")
2.2 AWS Keys
(require aws/keys) | package: aws |
2.2.1 Credential Parameters
Various parameters are used by add-v4-auth-heads to add Authorization and sometimes X-Amz-Security-Token headers to requests.
Although you may set these directly, see Initialization.
parameter
(public-key) → string?
(public-key key) → void? key : string?
= ""
parameter
(private-key) → string?
(private-key key) → void? key : string?
= ""
parameter
(security-token) → (or/c #f string?)
(security-token token) → void? token : (or/c #f string?)
= #f
Added in version 1.15 of package aws.
2.2.2 Initialization
The source of credentials depends on where your code is running. This package provides functions to initialize the Credential Parameters for various scenarios:
Credentials source
Example
Use
AWS CLI configuration file
Your PC
Environment variables
AWS Lambda
EC2 instance metadata
AWS EC2
procedure
parameter
(aws-cli-credentials path) → void? path : path-string?
=
(or (getenv "AWS_SHARED_CREDENTIALS_FILE") (build-path (find-system-path 'home-dir) ".aws" "credentials"))
parameter
(aws-cli-profile name) → void? name : string?
=
(or (getenv "AWS_DEFAULT_PROFILE") "default")
Parameter
Configuration file item
aws_access_key_id
aws_secret_access_key
Added in version 1.15 of package aws.
procedure
Parameter
Environment variable
AWS_ACCESS_KEY_ID
AWS_SECRET_ACCESS_KEY
AWS_SESSION_TOKEN
Added in version 1.15 of package aws.
procedure
(credentials-from-ec2-instance! iam-role-name) → void?
iam-role-name : string?
When running on EC2, you can obtain from EC2 instance metadata temporary credentials for an IAM role. This is easier to manage securely than using configuration files or environment variables.
For more information how to configure this, see “IAM Roles for Amazon EC2”.
Step five of those instructions —
Added in version 1.15 of package aws.
2.2.3 Deprecated
procedure
file : path? = (build-path(find-system-path 'home-dir) ".aws-keys")
AWSAccessKeyId=<key> |
AWSSecretKey=<key> |
By default this file is ~/.aws-keys. You probably want to chmod the permissions of this file carefully.
NOTE: This function is deprecated; use credentials-from-file!, instead. See also credentials-from-environment! and credentials-from-ec2-instance!.
procedure
Although a number of functions in this package call ensure-have-keys in an effort to "just work" even if you haven’t yet set the public and private keys, it’s probably smarter if you don’t call it yourself. (It remains provided only to avoid breaking existing dependents.) Instead you should set the keys explicitly yourself, before calling functions that need them.
NOTE: This function is deprecated; use credentials-from-file!, instead. See also credentials-from-environment! and credentials-from-ec2-instance!.
procedure
NOTE: This function is deprecated; use credentials-from-file!, instead. See also credentials-from-environment! and credentials-from-ec2-instance!.
Added in version 1.10 of package aws.
procedure
NOTE: This function is deprecated; use credentials-from-ec2-instance!, instead. See also credentials-from-file! and credentials-from-environment!
Added in version 1.10 of package aws.
2.3 Request authorization
(require aws/sigv4) | package: aws |
procedure
(add-v4-auth-heads #:heads heads #:method method #:uri uri #:sha256 sha256 #:region region #:service service) → dict? heads : dict? method : string uri : string? sha256 : string? region : string? service : string?
Added in version 1.12 of package aws.
Given a dict? of HTTP request headers, add one or more headers required by AWS for authorization:
Authorization: The value is calculated using AWS version 4 request signing.
X-Amz-Security-Token: This header is added when the security-token parameter is not #f, typically because:
You used credentials-from-ec2-instance! therefore the token is automatically obtained periodically from EC2 instance metadata.
You used credentials-from-environment! to get credentials from environment variables set by AWS Lambda.
Various functions in this library that make requests, use this
function. As a result, you will probably not need to use it directly
—
2.4 Exception handling
Most of the functions do not return a failure value. Instead they raise exn:fail:aws, which you need to “catch” using with-handlers.
(require aws/exn) | package: aws |
struct
(struct exn:fail:aws (http-code http-message aws-code aws-message) #:extra-constructor-name make-exn:fail:aws) http-code : exact-positive-integer? http-message : string? aws-code : string? aws-message : string?
procedure
(header&response->exn:fail:aws headers body ccm) → exn:fail:aws? headers : string? body : (or/c bytes? xexpr?) ccm : continuation-mark-set?
procedure
(check-response in headers)
→ (or/c string? (raise/c exn:fail:aws?)) in : input-port? headers : string?
Otherwise, read the XML response body from in and use the information to construct and raise exn:fail:aws.
Note: This does not close the input port in before raising an
exception. It assumes you are using call/requests,
call/input-request, or call/output-request from the
http/request library (or using dynamic-wind or other
exception handling, or a custodian—
2.5 Connection pooling
This library uses the http package to make HTTP connections to AWS. You may cause connections to be reused ("pooled") by setting the current-pool-timeout parameter to some non-zero number of seconds.
This can be faster, especially for many small requests in a row.
In the following example, the first list-buckets request will leave the connection open for 30 seconds. As a result, the second list-buckets request will reuse the same connection. After another 30 seconds, the connection will be closed automatically.
(require http/request aws/s3) (parameterize ([current-pool-timeout 30]) (list-buckets) (list-buckets))