-
-
Notifications
You must be signed in to change notification settings - Fork 51
AWS S3 Storage
In order to use S3 you need to reference
package first. The provider wraps around the standard AWS SDK which is updated regularly, but adds a lot of untrivial workarounds that makes your life painless.
There are a few overloads in this package, for instance:
IBlobStorage storage = StorageFactory.Blobs.AwsS3(string accessKeyId,
string secretAccessKey,
string sessionToken,
string bucketName,
RegionEndpoint regionEndpoint = null);
IBlobStorage storage = StorageFactory.Blobs.DigitalOceanSpaces(string accessKeyId,
string secretAccessKey,
string bucketName,
string digitalOceanRegion,
string sessionToken = null);
IBlobStorage storage = StorageFactory.Blobs.MinIO(string accessKeyId,
string secretAccessKey,
string bucketName,
string awsRegion,
string minioServerUrl,
string sessionToken = null);
To create with a connection string, first reference the module:
StorageFactory.Modules.UseAwsStorage();
Then construct using the following format:
IBlobStorage storage = StorageFactory.Blobs.FromConnectionString("aws.s3://keyId=...;key=...;bucket=...;region=...");
where:
- keyId is (optional) access key ID.
- key is (optional) secret access key.
- bucket is bucket name.
-
region is the AWS account region (such as
us-east-1
). - serviceUrl is the optional URL of the storage provider (for example for DigitalOcean).
If keyId and key are omitted, the AWS SDK's default approach to credential resolution will be used. For example: if running in Lambda, it will assume the Lambda execution role; if there are credentials configured in ~/.aws, it will use those; etc. See AWS SDK Documentation for more details.
If you already have credentials in the local ~/.aws/credentials
generated by AWS CLI, you can also use them to connect to a bucket with FluentStorage. Credentials file example:
[default]
aws_access_key_id = ASIAV44FYRYLSBYIPG67
aws_secret_access_key = zhuh8nSUAR0pR5jbi4vhUym95JsC7ay3iiE2v9Jq
aws_session_token = FQoGZXIvY...
[anotherProfile]
aws_access_key_id = ASIAXEKXYP2H7MRN45FD
aws_secret_access_key = 8i6jnOOurRtTiK4CWN+uUD115SYS8++ZuQjO/LtW
aws_session_token = FQoGZXI...
...
To connect using say anotherProfile
credentials, construct the instance by:
IBlobStorage bs = StorageFactory.Blobs.AwsS3(
"anotherProfile",
"bucketName",
"region");
AwsCliCredentials class contains credentials
file parrsing logic and some utility methods you mind find useful, for instance enumerating available profiles and so on.
Native operations are exposed via IAwsS3BlobStorageNativeOperations interface.