0%
خدمات AWS الأساسية: دليل شامل

خدمات AWS الأساسية: دليل شامل

تعرّف على خدمات AWS الأساسية، من البنية التحتية إلى إدارة البيانات.

I

InSkillCoach

· دقيقة

خدمات AWS الأساسية: دليل شامل

تعرّف على أهم خدمات AWS وحالات استخدامها الشائعة.

1. خدمات الحوسبة

Amazon EC2 (Elastic Compute Cloud)

# مثال على إنشاء نسخة EC2 باستخدام boto3
import boto3

def create_ec2_instance():
    ec2 = boto3.client('ec2')
    
    response = ec2.run_instances(
        ImageId='ami-0c55b159cbfafe1f0',  # Amazon Linux 2 AMI
        InstanceType='t2.micro',
        MinCount=1,
        MaxCount=1,
        KeyName='ma-clé',
        SecurityGroupIds=['sg-xxxxxxxx'],
        TagSpecifications=[
            {
                'ResourceType': 'instance',
                'Tags': [
                    {'Key': 'Name', 'Value': 'mon-instance'},
                    {'Key': 'Environnement', 'Value': 'Production'}
                ]
            }
        ]
    )
    
    return response['Instances'][0]['InstanceId']

AWS Lambda

# مثال على دالة Lambda
import json

def lambda_handler(event, context):
    try:
        # معالجة البيانات
        body = json.loads(event['body'])
        result = process_data(body)
        
        return {
            'statusCode': 200,
            'body': json.dumps({
                'message': 'Succès',
                'result': result
            })
        }
    except Exception as e:
        return {
            'statusCode': 500,
            'body': json.dumps({
                'message': 'Erreur',
                'error': str(e)
            })
        }

2. خدمات التخزين

Amazon S3 (Simple Storage Service)

# مثال على استخدام S3
import boto3

def upload_to_s3(file_path, bucket_name, object_name):
    s3 = boto3.client('s3')
    
    try:
        s3.upload_file(file_path, bucket_name, object_name)
        return True
    except Exception as e:
        print(f"Erreur lors de l'upload: {e}")
        return False

def download_from_s3(bucket_name, object_name, file_path):
    s3 = boto3.client('s3')
    
    try:
        s3.download_file(bucket_name, object_name, file_path)
        return True
    except Exception as e:
        print(f"Erreur lors du téléchargement: {e}")
        return False

Amazon EBS (Elastic Block Store)

# مثال على إدارة وحدات تخزين EBS
import boto3

def create_ebs_volume(availability_zone, size_gb):
    ec2 = boto3.client('ec2')
    
    response = ec2.create_volume(
        AvailabilityZone=availability_zone,
        Size=size_gb,
        VolumeType='gp3',
        TagSpecifications=[
            {
                'ResourceType': 'volume',
                'Tags': [
                    {'Key': 'Name', 'Value': 'mon-volume'},
                    {'Key': 'Type', 'Value': 'Données'}
                ]
            }
        ]
    )
    
    return response['VolumeId']

3. خدمات قواعد البيانات

Amazon RDS (Relational Database Service)

# مثال على الاتصال بـ RDS
import mysql.connector

def connect_to_rds():
    try:
        connection = mysql.connector.connect(
            host='mon-instance.xxxxx.region.rds.amazonaws.com',
            user='admin',
            password='mon-mot-de-passe',
            database='ma_base'
        )
        return connection
    except Exception as e:
        print(f"Erreur de connexion: {e}")
        return None

Amazon DynamoDB

# مثال على استخدام DynamoDB
import boto3

def create_dynamodb_item(table_name, item):
    dynamodb = boto3.resource('dynamodb')
    table = dynamodb.Table(table_name)
    
    try:
        response = table.put_item(Item=item)
        return response
    except Exception as e:
        print(f"Erreur lors de la création: {e}")
        return None

4. خدمات الشبكات

Amazon VPC (Virtual Private Cloud)

# مثال على إنشاء VPC
import boto3

def create_vpc():
    ec2 = boto3.client('ec2')
    
    # إنشاء VPC
    vpc_response = ec2.create_vpc(
        CidrBlock='10.0.0.0/16',
        TagSpecifications=[
            {
                'ResourceType': 'vpc',
                'Tags': [
                    {'Key': 'Name', 'Value': 'mon-vpc'},
                    {'Key': 'Environnement', 'Value': 'Production'}
                ]
            }
        ]
    )
    
    # إنشاء شبكة فرعية عامة
    subnet_response = ec2.create_subnet(
        VpcId=vpc_response['Vpc']['VpcId'],
        CidrBlock='10.0.1.0/24',
        AvailabilityZone='eu-west-3a'
    )
    
    return {
        'vpc_id': vpc_response['Vpc']['VpcId'],
        'subnet_id': subnet_response['Subnet']['SubnetId']
    }

Amazon Route 53

# مثال على إدارة DNS باستخدام Route 53
import boto3

def create_dns_record(zone_id, domain_name, record_type, value):
    route53 = boto3.client('route53')
    
    response = route53.change_resource_record_sets(
        HostedZoneId=zone_id,
        ChangeBatch={
            'Changes': [
                {
                    'Action': 'CREATE',
                    'ResourceRecordSet': {
                        'Name': domain_name,
                        'Type': record_type,
                        'TTL': 300,
                        'ResourceRecords': [
                            {'Value': value}
                        ]
                    }
                }
            ]
        }
    )
    
    return response['ChangeInfo']['Id']

5. خدمات الأمان

AWS IAM (Identity and Access Management)

# مثال على إنشاء مستخدم IAM
import boto3

def create_iam_user(username):
    iam = boto3.client('iam')
    
    try:
        # إنشاء المستخدم
        user_response = iam.create_user(UserName=username)
        
        # إرفاق سياسة
        iam.attach_user_policy(
            UserName=username,
            PolicyArn='arn:aws:iam::aws:policy/PowerUserAccess'
        )
        
        return user_response['User']['UserName']
    except Exception as e:
        print(f"Erreur lors de la création: {e}")
        return None

AWS KMS (Key Management Service)

# مثال على استخدام KMS
import boto3

def encrypt_data(key_id, data):
    kms = boto3.client('kms')
    
    try:
        response = kms.encrypt(
            KeyId=key_id,
            Plaintext=data.encode('utf-8')
        )
        return response['CiphertextBlob']
    except Exception as e:
        print(f"Erreur de chiffrement: {e}")
        return None

الخلاصة

النقاط الأساسية التي ينبغي تذكّرها:

  • اختيار الخدمات المناسبة وفق الاحتياجات
  • تحسين التكاليف
  • تطبيق الأمان منذ البداية
  • استخدام أفضل ممارسات AWS
  • مراقبة الأداء

الخدمات الأساسية:

  • EC2 للحوسبة
  • S3 للتخزين
  • RDS لقواعد البيانات العلائقية
  • DynamoDB لقواعد بيانات NoSQL
  • VPC للشبكات
  • IAM للأمان
InSkillCoach

نبذة عن InSkillCoach

خبير في التدريب والتقنيات

مدرّب متخصص في التقنيات المتقدمة والذكاء الاصطناعي، تدعمه شركة GNeurone Inc.

الشهادات:

  • AWS Certified Solutions Architect – Professional
  • شهادات Google Cloud
  • Microsoft Certified: DevOps Engineer Expert
  • Certified Kubernetes Administrator (CKA)
  • CompTIA Security+
1.3k
259

التعليقات

التعليقات مدعومة عبر GitHub Discussions

سجّل الدخول باستخدام GitHub للمشاركة في النقاش

تم نسخ الرابط!