AWS4

1.0.0

AWS4 implementation in Swift for usage in MacOS >= 10.15 or iOS >= 13
kortac/AWS4

What's New

1.0.0

2022-08-22T11:30:20Z

1.0.0 (2022-08-22)

Bug Fixes

  • accessibility of functions and enum (e470d8d)
  • downgrade swift-tools-version to 5.5 (cd4446e)
  • fix encoding of paths (662e82a)
  • remove v from tags (574f1be)

Features

  • add AWS4 class with basic support for IAM (c3bc4a9)

AWS4

Badge

Basic implementation of AWS Signature Version 4 in Swift for MacOS >= 10.15 and iOS >= 13.

Currently only ElasticSearch (es), IAM (iam) and some S3 (s3) services supported. Others may be added in the future. Feel free to open pull requests!

Installation

Swift Package Manager

.Package(url: "https://github.com/s5zy/AWS4.git", .upToNextMajor(from: "1.0.0"))
.Package(url: "https://github.com/s5zy/AWS4.git", branch: "main")

Quick Guide

General

# Initialize from Info.plist
let aws = AWS4()

# Sign a request
let signed = aws.sign(request: req, for: .iam)

Credentials

Your credentials will be retrieved from Info.plist if you don't provide them to the initializer. We recommend to store them in your .xcconfig file! Please use

  • AWS_ACCESSKEYID for your access key
  • AWS_SECRETACCESSKEY for your secret access key
  • AWS_REGION for your AWS region

In addition you can also pass them directly to AWS4(), however we do not (⚠️) recommend to hardcode your credentials!

let aws = AWS4(region: "us-east-1",
               accessKeyId: "AKIDEXAMPLE",
               secretAccessKey: "wJalrXUtnFEMI/K7MDENG+bPxRfiCYEXAMPLEKEY")

Custom date

If you have to use a different datetime than the current one, just pass it to .sign:

let signed = aws.sign(request: req, for: .iam, date: date)

URLRequest

An URLRequest extension that creates the required headers is implemented by us.

Attention: Do not change any headers, params, body data, path, ... after calling signed()!

let url = URL(string: "https://search-test-xxxxxxxxxxxxxxxxxxxxxxxxxx.eu-central-1.es.amazonaws.com")!
var req = URLRequest(url: url)
req.addValue("application/json; charset=utf-8", forHTTPHeaderField: "Content-Type")

let (data, _) = try await session.data(for: req.signed(service: .es))

Description

  • Swift Tools 5.5.0
View More Packages from this Author

Dependencies

  • None
Last updated: Thu Nov 17 2022 08:27:14 GMT-1000 (Hawaii-Aleutian Standard Time)