Update README for latest code

This commit is contained in:
Adam Fowler 2020-02-01 17:14:44 +00:00
parent 6f799e7a9a
commit c8e382cd9a
1 changed files with 12 additions and 11 deletions

View File

@ -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))
```
@ -35,12 +35,12 @@ 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)
@ -48,6 +48,7 @@ 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