Skip to content

Commit

Permalink
Update README for latest code
Browse files Browse the repository at this point in the history
  • Loading branch information
adam-fowler committed Feb 1, 2020
1 parent 6f799e7 commit c8e382c
Showing 1 changed file with 12 additions and 11 deletions.
23 changes: 12 additions & 11 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -10,23 +10,23 @@ Create an AWSSigner object. Initialise it with security credentials for accessin
The following example code creates a signed URL to access a file in S3.

```
let credentials = Credential(accessKeyId: "MYACCESSKEY", secretAccessKey: "MYSECRETACCESSKEY")
let credentials = StaticCredential(accessKeyId: "MYACCESSKEY", secretAccessKey: "MYSECRETACCESSKEY")
let signer = AWSSigner(credentials: credentials, name: "s3", region: "us-east-1")
let signedURL = AWSSigner.signURL(
url: URL(string:"mybucket.s3.us-east-1.amazonaws.com/myfile")!,
let signedURL = signer.signURL(
url: URL(string:"mybucket.s3.us-east-1.amazonaws.com/myfile")!,
method: .GET)
```

Alternatively you can store the authentication details in the request headers. The following returns the headers required to sign a request plus the original headers. The signature is stored in the 'Authorization' header. This request will return a response containing a list of SNS Topics from AWS region us-east-1.

```
let credentials = Credential(accessKeyId: "MYACCESSKEY", secretAccessKey: "MYSECRETACCESSKEY")
let credentials = StaticCredential(accessKeyId: "MYACCESSKEY", secretAccessKey: "MYSECRETACCESSKEY")
let signer = AWSSigner(credentials: credentials, name: "sns", region: "us-east-1")
let body = "Action=ListTopics&Version=2010-03-31"
let signedHeaders = AWSSigner.signHeaders(
url: URL(string:"sns.us-east-1.amazonaws.com/")!,
method: .GET,
headers: ["Content-Type": "application/x-www-form-urlencoded; charset=utf-8"],
let signedHeaders = signer.signHeaders(
url: URL(string:"sns.us-east-1.amazonaws.com/")!,
method: .GET,
headers: ["Content-Type": "application/x-www-form-urlencoded; charset=utf-8"],
body: .string(body))
```

Expand All @@ -35,19 +35,20 @@ The library includes extensions to the HTTPClient of [AsyncHttpClient](https://g

Both `HTTPClient.awsURLSignedRequest()` and `HTTPClient.awsHeaderSignedRequest()` will create a signed Request that can be sent to AWS via the HTTPClient from AsyncHttpClient. The following creates a signed S3 Request to upload a file to an S3 bucket and processes it.
```
let credentials = Credential(accessKeyId: "MYACCESSKEY", secretAccessKey: "MYSECRETACCESSKEY")
let credentials = StaticCredential(accessKeyId: "MYACCESSKEY", secretAccessKey: "MYSECRETACCESSKEY")
let signer = AWSSigner(credentials: credentials, name: "s3", region: "us-east-1")
let body = "FileContents"
let request = try HTTPClient.awsURLSignedRequest(
url: URL(string:"mybucket.s3.us-east-1.amazonaws.com/mynewfile")!,
method: .PUT,
url: URL(string:"mybucket.s3.us-east-1.amazonaws.com/mynewfile")!,
method: .PUT,
body: .string(body),
signer: signer)
let client = HTTPClient(eventLoopGroupProvider: .createNew)
client.execute(request: request).whenComplete { result in
switch result {
case .failure(let error):
// process error
break
case .success(let response):
if response.status == .ok {
// handle response
Expand Down

0 comments on commit c8e382c

Please sign in to comment.