احراز هویت
برای استفاده از فضای ابری، شما نیازمند Access Key،Secret Key و آدرس اتصال (Endpoint URL) هستید.
شیوه دریافت کلیدهای احراز هویت
در پیشخان سرویس فضای ابری، میتوانید Access key و Secret Key مربوط به حساب کاربری خود را نیز مشاهده کنید.
برای احراز هویت میتوانید با قرار دادن Access Key و Secret Key در قطعه کد زیر این فرآیند را انجام دهید.
- 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',
},
});
گام نخست: قرار دادن Access Key و Secret Key در فایل مانند زیر:
mkdir ~/.aws && touch ~/.aws/credentials
echo "[default]
aws_access_key_id = <ACCESS_KEY>
aws_secret_access_key = <SECRET_KEY>" > ~/.aws/credentials
و اجرای قطعه کد زیر:
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>"),
})
}
گام دوم: قرار دادن Access Key و Secret Key به شکل hard-coded در کد مانند قطعه کد زیر:
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
}
}