Credentials
To use Object Storage you need Access Key, Secret Key, and Endpoint URL.
Get Credentials
In the dashboard of the Object Storage, you can see the Access key and Secret Key related to your user account.
For authentication, you can put Access Key and Secret Key in the following code snippet.
- .NET
- PHP
- Python
- Javascript
- GO
// Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved.
// SPDX - License - Identifier: Apache - 2.0
using Amazon.S3;
using Amazon.S3.Model;
using System;
using System.Threading.Tasks;
namespace CreateBucket
{
public class CreateBucket
{
// This example shows how to use Amazon Simple Storage Service (Amazon S3)
// to create a new Amazon S3 bucket. The examples uses AWS SDK for .NET 3.5 and
// .NET 5.0.
private static IAmazonS3 _s3Client;
static async Task Main()
{
var awsCredentials = new Amazon.Runtime.BasicAWSCredentials("<ACCESS-KEY>", "<SECRET-KEY>");
var config = new AmazonS3Config { ServiceURL = "<ENDPOINT>" };
_s3Client = new AmazonS3Client(awsCredentials, config);
// Continue your code here
}
}
}
<?php
use Aws\S3\S3Client;
define('AWS_KEY', 'place access key here');
define('AWS_SECRET_KEY', 'place secret key here');
$ENDPOINT = 'https://s3.ir-thr-at1.arvanstorage.ir'; //or https://s3.ir-tbz-sh1.arvanstorage.ir
// require the sdk from your composer vendor dir
require __DIR__.'/vendor/autoload.php';
// Instantiate the S3 class and point it at the desired host
$client = new S3Client([
'region' => '',
'version' => '2006-03-01',
'endpoint' => $ENDPOINT,
'credentials' => [
'key' => AWS_KEY,
'secret' => AWS_SECRET_KEY
],
// Set the S3 class to use objects. arvanstorage.ir/bucket
// instead of bucket.objects. arvanstorage.ir
'use_path_style_endpoint' => true
]);
import boto3
import logging
logging.basicConfig(level=logging.INFO)
try:
s3_resource = boto3.resource(
's3',
endpoint_url='endpoint_url',
aws_access_key_id='access_key',
aws_secret_access_key='secret_key'
)
except Exception as exc:
logging.info(exc)
const { S3Client } = require('@aws-sdk/client-s3');
const s3 = new S3Client({
region: 'default',
endpoint: 'endpoint_url',
credentials: {
accessKeyId: 'access_key',
secretAccessKey: 'secret_key',
},
});
First: put Access Key and Secret Key in the file as below:
mkdir ~/.aws && touch ~/.aws/credentials
echo "[default]
aws_access_key_id = <ACCESS_KEY>
aws_secret_access_key = <SECRET_KEY>" > ~/.aws/credentials
And execute the following code snippet:
package main
import (
"fmt"
"os"
"github.com/aws/aws-sdk-go/aws"
"github.com/aws/aws-sdk-go/aws/session"
"github.com/aws/aws-sdk-go/service/s3"
)
func main() {
sess := session.Must(session.NewSessionWithOptions(session.Options{
SharedConfigState: session.SharedConfigEnable,
}))
svc := s3.New(sess, &aws.Config{
Region: aws.String("default"),
Endpoint: aws.String("<ENDPOINT_URL>"),
})
}
Second: Hard-code Access Key and Secret Key in the code like the following code snippet:
package main
import (
"fmt"
"os"
"github.com/aws/aws-sdk-go/aws"
"github.com/aws/aws-sdk-go/aws/credentials"
"github.com/aws/aws-sdk-go/aws/session"
"github.com/aws/aws-sdk-go/service/s3"
)
func main() {
sess, err := session.NewSession(&aws.Config{
Credentials: credentials.NewStaticCredentials("<ACCESS_KEY>", "<SECRET_KEY>", ""),
})
svc := s3.New(sess, &aws.Config{
Region: aws.String("default"),
Endpoint: aws.String("<ENDPOINT_URL>"),
})
if err != nil {
// handle error
} else {
// success
}
}