

Le traduzioni sono generate tramite traduzione automatica. In caso di conflitto tra il contenuto di una traduzione e la versione originale in Inglese, quest'ultima prevarrà.

# Tutorial di avvio rapido per Amazon Managed Workflows for Apache Airflow
<a name="quick-start"></a>

Questo tutorial di avvio rapido utilizza un AWS CloudFormation modello che crea insieme l'infrastruttura Amazon VPC, un bucket Amazon S3 con una cartella e `dags` un ambiente Amazon Managed Workflows for Apache Airflow.

**Topics**
+ [In questo tutorial](#quick-start-overview)
+ [Prerequisiti](#quick-start-before)
+ [Fase uno: salvare il CloudFormation modello localmente](#quick-start-template)
+ [Fase due: creare lo stack utilizzando il AWS CLI](#quick-start-createstack)
+ [Fase tre: caricare un DAG su Amazon S3 ed eseguirlo nell'interfaccia utente di Apache Airflow](#quick-start-upload-dag)
+ [Fase quattro: accedere ai log in Logs CloudWatch](#quick-start-logs)
+ [Fasi successive](#quick-start-next-up)

## In questo tutorial
<a name="quick-start-overview"></a>

Usa questo tutorial per caricare un DAG su Amazon S3, eseguire il DAG in Apache Airflow e accedere ai log in utilizzando tre comandi (). CloudWatch AWS Command Line Interface AWS CLI Infine, imparerai a creare una policy IAM per un team di sviluppo di Apache Airflow.

**Nota**  
Il CloudFormation modello in questa pagina crea un ambiente Amazon Managed Workflows for Apache Airflow per l'ultima versione di Apache Airflow disponibile in. CloudFormation L'ultima versione disponibile è Apache Airflow v3.0.6.

Il CloudFormation modello crea quanto segue:
+ **Infrastruttura VPC.** Il modello utilizza[Routing pubblico su Internet](networking-about.md#networking-about-overview-public). Utilizza il server [Modalità di accesso alla rete pubblica](configuring-networking.md#access-overview-public) web Apache Airflow in. `WebserverAccessMode: PUBLIC_ONLY`
+ **Bucket Amazon S3**. Il modello crea un bucket Amazon S3 con una cartella. `dags` È configurato per **bloccare tutti gli accessi pubblici**, con **Bucket Versioning** abilitato, come definito in. [Crea un bucket Amazon S3 per Amazon MWAA](mwaa-s3-bucket.md)
+ Ambiente **Amazon MWAA**. Il modello crea un ambiente Amazon MWAA associato alla `dags` cartella nel bucket Amazon S3, un ruolo di esecuzione con autorizzazione ai AWS servizi utilizzati da Amazon MWAA e l'impostazione predefinita per la crittografia utilizzando [AWS una](https://docs.aws.amazon.com/kms/latest/developerguide/concepts.html#aws-owned-cmk) chiave di proprietà, come definito in. [Crea un ambiente Amazon MWAA](create-environment.md)
+ **CloudWatch Registri.** *Il modello attiva gli accessi CloudWatch di Apache Airflow a livello INFO e versioni successive per **il** gruppo di log dello *scheduler Airflow, il gruppo di log del server web Airflow, il gruppo di log* *di lavoro Airflow, il gruppo di log* *di elaborazione Airflow DAG e il gruppo di log* *delle attività Airflow, come definito* in.* [Accesso ai log Airflow in Amazon CloudWatch](monitoring-airflow.md)

In questo tutorial, completerai le seguenti attività:
+ **Carica ed esegui un DAG**. Carica il tutorial DAG di Apache Airflow per l'ultima versione di Apache Airflow supportata da Amazon MWAA su Amazon S3, quindi eseguilo nell'interfaccia utente di Apache Airflow, come definito in. [Aggiungere o aggiornare DAGs](configuring-dag-folder.md)
+ **Registri di accesso.** Accedere al *gruppo di log del server web Airflow* in CloudWatch Logs, come definito in. [Accesso ai log Airflow in Amazon CloudWatch](monitoring-airflow.md)
+ **Crea una politica di controllo degli accessi**. Crea una policy di controllo degli accessi in IAM per il tuo team di sviluppo di Apache Airflow, come definito in. [Accesso a un ambiente Amazon MWAA](access-policies.md)

**Nota**  
Nel VPC che ospita l'ambiente Amazon MWAA, impostato su per tutte le sottoreti `assignIpv6AddressOnCreation` `true` collegate. Questa impostazione garantisce l'assegnazione automatica degli indirizzi del protocollo Internet versione 6 (IPv6) alle risorse all'interno di queste sottoreti.

## Prerequisiti
<a name="quick-start-before"></a>

Il AWS Command Line Interface (AWS CLI) è uno strumento open source che è possibile utilizzare per interagire con i AWS servizi utilizzando i comandi nella shell della riga di comando. Per completare la procedura descritta in questa pagina, è necessario quanto segue:
+ [AWS CLI — Installa la versione 2](https://docs.aws.amazon.com/cli/latest/userguide/install-cliv2.html).
+ [AWS CLI — Configurazione rapida con `aws configure`](https://docs.aws.amazon.com/cli/latest/userguide/cli-chap-configure.html).

## Fase uno: salvare il CloudFormation modello localmente
<a name="quick-start-template"></a>
+ Copia il contenuto del seguente modello e salvalo localmente con nome`mwaa-public-network.yml`. Puoi anche [scaricare il modello](./samples/mwaa-public-network.zip).

  ```
  AWSTemplateFormatVersion: "2010-09-09"
  
  Parameters:
  
    EnvironmentName:
      Description: An environment name that is prefixed to resource names
      Type: String
      Default: MWAAEnvironment
  
    VpcCIDR:
      Description: The IP range (CIDR notation) for this VPC
      Type: String
      Default: 10.192.0.0/16
  
    PublicSubnet1CIDR:
      Description: The IP range (CIDR notation) for the public subnet in the first Availability Zone
      Type: String
      Default: 10.192.10.0/24
  
    PublicSubnet2CIDR:
      Description: The IP range (CIDR notation) for the public subnet in the second Availability Zone
      Type: String
      Default: 10.192.11.0/24
  
    PrivateSubnet1CIDR:
      Description: The IP range (CIDR notation) for the private subnet in the first Availability Zone
      Type: String
      Default: 10.192.20.0/24
    PrivateSubnet2CIDR:
      Description: The IP range (CIDR notation) for the private subnet in the second Availability Zone
      Type: String
      Default: 10.192.21.0/24
    MaxWorkerNodes:
      Description: The maximum number of workers that can run in the environment
      Type: Number
      Default: 2
    DagProcessingLogs:
      Description: Log level for DagProcessing
      Type: String
      Default: INFO
    SchedulerLogsLevel:
      Description: Log level for SchedulerLogs
      Type: String
      Default: INFO
    TaskLogsLevel:
      Description: Log level for TaskLogs
      Type: String
      Default: INFO
    WorkerLogsLevel:
      Description: Log level for WorkerLogs
      Type: String
      Default: INFO
    WebserverLogsLevel:
      Description: Log level for WebserverLogs
      Type: String
      Default: INFO
  
  Resources:
    #####################################################################################################################
    # CREATE VPC
    #####################################################################################################################
  
    VPC:
      Type: AWS::EC2::VPC
      Properties:
        CidrBlock: !Ref VpcCIDR
        EnableDnsSupport: true
        EnableDnsHostnames: true
        Tags:
          - Key: Name
            Value: MWAAEnvironment
  
    InternetGateway:
      Type: AWS::EC2::InternetGateway
      Properties:
        Tags:
          - Key: Name
            Value: MWAAEnvironment
  
    InternetGatewayAttachment:
      Type: AWS::EC2::VPCGatewayAttachment
      Properties:
        InternetGatewayId: !Ref InternetGateway
        VpcId: !Ref VPC
  
    PublicSubnet1:
      Type: AWS::EC2::Subnet
      Properties:
        VpcId: !Ref VPC
        AvailabilityZone: !Select [ 0, !GetAZs '' ]
        CidrBlock: !Ref PublicSubnet1CIDR
        MapPublicIpOnLaunch: true
        Tags:
          - Key: Name
            Value: !Sub ${EnvironmentName} Public Subnet (AZ1)
  
    PublicSubnet2:
      Type: AWS::EC2::Subnet
      Properties:
        VpcId: !Ref VPC
        AvailabilityZone: !Select [ 1, !GetAZs  '' ]
        CidrBlock: !Ref PublicSubnet2CIDR
        MapPublicIpOnLaunch: true
        Tags:
          - Key: Name
            Value: !Sub ${EnvironmentName} Public Subnet (AZ2)
  
    PrivateSubnet1:
      Type: AWS::EC2::Subnet
      Properties:
        VpcId: !Ref VPC
        AvailabilityZone: !Select [ 0, !GetAZs  '' ]
        CidrBlock: !Ref PrivateSubnet1CIDR
        MapPublicIpOnLaunch: false
        Tags:
          - Key: Name
            Value: !Sub ${EnvironmentName} Private Subnet (AZ1)
  
    PrivateSubnet2:
      Type: AWS::EC2::Subnet
      Properties:
        VpcId: !Ref VPC
        AvailabilityZone: !Select [ 1, !GetAZs  '' ]
        CidrBlock: !Ref PrivateSubnet2CIDR
        MapPublicIpOnLaunch: false
        Tags:
          - Key: Name
            Value: !Sub ${EnvironmentName} Private Subnet (AZ2)
  
    NatGateway1EIP:
      Type: AWS::EC2::EIP
      DependsOn: InternetGatewayAttachment
      Properties:
        Domain: vpc
  
    NatGateway2EIP:
      Type: AWS::EC2::EIP
      DependsOn: InternetGatewayAttachment
      Properties:
        Domain: vpc
  
    NatGateway1:
      Type: AWS::EC2::NatGateway
      Properties:
        AllocationId: !GetAtt NatGateway1EIP.AllocationId
        SubnetId: !Ref PublicSubnet1
  
    NatGateway2:
      Type: AWS::EC2::NatGateway
      Properties:
        AllocationId: !GetAtt NatGateway2EIP.AllocationId
        SubnetId: !Ref PublicSubnet2
  
    PublicRouteTable:
      Type: AWS::EC2::RouteTable
      Properties:
        VpcId: !Ref VPC
        Tags:
          - Key: Name
            Value: !Sub ${EnvironmentName} Public Routes
  
    DefaultPublicRoute:
      Type: AWS::EC2::Route
      DependsOn: InternetGatewayAttachment
      Properties:
        RouteTableId: !Ref PublicRouteTable
        DestinationCidrBlock: 0.0.0.0/0
        GatewayId: !Ref InternetGateway
  
    PublicSubnet1RouteTableAssociation:
      Type: AWS::EC2::SubnetRouteTableAssociation
      Properties:
        RouteTableId: !Ref PublicRouteTable
        SubnetId: !Ref PublicSubnet1
  
    PublicSubnet2RouteTableAssociation:
      Type: AWS::EC2::SubnetRouteTableAssociation
      Properties:
        RouteTableId: !Ref PublicRouteTable
        SubnetId: !Ref PublicSubnet2
  
  
    PrivateRouteTable1:
      Type: AWS::EC2::RouteTable
      Properties:
        VpcId: !Ref VPC
        Tags:
          - Key: Name
            Value: !Sub ${EnvironmentName} Private Routes (AZ1)
  
    DefaultPrivateRoute1:
      Type: AWS::EC2::Route
      Properties:
        RouteTableId: !Ref PrivateRouteTable1
        DestinationCidrBlock: 0.0.0.0/0
        NatGatewayId: !Ref NatGateway1
  
    PrivateSubnet1RouteTableAssociation:
      Type: AWS::EC2::SubnetRouteTableAssociation
      Properties:
        RouteTableId: !Ref PrivateRouteTable1
        SubnetId: !Ref PrivateSubnet1
  
    PrivateRouteTable2:
      Type: AWS::EC2::RouteTable
      Properties:
        VpcId: !Ref VPC
        Tags:
          - Key: Name
            Value: !Sub ${EnvironmentName} Private Routes (AZ2)
  
    DefaultPrivateRoute2:
      Type: AWS::EC2::Route
      Properties:
        RouteTableId: !Ref PrivateRouteTable2
        DestinationCidrBlock: 0.0.0.0/0
        NatGatewayId: !Ref NatGateway2
  
    PrivateSubnet2RouteTableAssociation:
      Type: AWS::EC2::SubnetRouteTableAssociation
      Properties:
        RouteTableId: !Ref PrivateRouteTable2
        SubnetId: !Ref PrivateSubnet2
  
    SecurityGroup:
      Type: AWS::EC2::SecurityGroup
      Properties:
        GroupName: "mwaa-security-group"
        GroupDescription: "Security group with a self-referencing inbound rule."
        VpcId: !Ref VPC
  
    SecurityGroupIngress:
      Type: AWS::EC2::SecurityGroupIngress
      Properties:
        GroupId: !Ref SecurityGroup
        IpProtocol: "-1"
        SourceSecurityGroupId: !Ref SecurityGroup
  
    EnvironmentBucket:
      Type: AWS::S3::Bucket
      Properties:
        VersioningConfiguration:
          Status: Enabled
        PublicAccessBlockConfiguration: 
          BlockPublicAcls: true
          BlockPublicPolicy: true
          IgnorePublicAcls: true
          RestrictPublicBuckets: true
  
    #####################################################################################################################
    # CREATE MWAA
    #####################################################################################################################
  
    MwaaEnvironment:
      Type: AWS::MWAA::Environment
      DependsOn: MwaaExecutionPolicy
      Properties:
        Name: !Sub "${AWS::StackName}-MwaaEnvironment"
        SourceBucketArn: !GetAtt EnvironmentBucket.Arn
        ExecutionRoleArn: !GetAtt MwaaExecutionRole.Arn
        DagS3Path: dags/  
        NetworkConfiguration:
          SecurityGroupIds:
            - !GetAtt SecurityGroup.GroupId
          SubnetIds:
            - !Ref PrivateSubnet1
            - !Ref PrivateSubnet2
        WebserverAccessMode: PUBLIC_ONLY
        MaxWorkers: !Ref MaxWorkerNodes
        LoggingConfiguration:
          DagProcessingLogs:
            LogLevel: !Ref DagProcessingLogs
            Enabled: true
          SchedulerLogs:
            LogLevel: !Ref SchedulerLogsLevel
            Enabled: true
          TaskLogs:
            LogLevel: !Ref TaskLogsLevel
            Enabled: true
          WorkerLogs:
            LogLevel: !Ref WorkerLogsLevel
            Enabled: true
          WebserverLogs:
            LogLevel: !Ref WebserverLogsLevel
            Enabled: true
  
    MwaaExecutionRole:
      Type: AWS::IAM::Role
      Properties:
        AssumeRolePolicyDocument:
          Version: 2012-10-17&TCX5-2025-waiver;
          Statement:
            - Effect: Allow
              Principal:
                Service:
                  - airflow-env.amazonaws.com
                  - airflow.amazonaws.com
              Action:
               - "sts:AssumeRole"
        Path: "/service-role/"
  
    MwaaExecutionPolicy:
      DependsOn: EnvironmentBucket
      Type: AWS::IAM::ManagedPolicy
      Properties:
        Roles:
          - !Ref MwaaExecutionRole
        PolicyDocument:
          Version: 2012-10-17&TCX5-2025-waiver;
          Statement:
            - Effect: Allow
              Action: airflow:PublishMetrics
              Resource:
                - !Sub "arn:aws:airflow:${AWS::Region}:${AWS::AccountId}:environment/${EnvironmentName}"
            - Effect: Deny
              Action: s3:ListAllMyBuckets
              Resource:
                - !Sub "${EnvironmentBucket.Arn}"
                - !Sub "${EnvironmentBucket.Arn}/*"
  
            - Effect: Allow
              Action:
                - "s3:GetObject*"
                - "s3:GetBucket*"
                - "s3:List*"
              Resource:
                - !Sub "${EnvironmentBucket.Arn}"
                - !Sub "${EnvironmentBucket.Arn}/*"
            - Effect: Allow
              Action:
                - logs:DescribeLogGroups
              Resource: "*"
  
            - Effect: Allow
              Action:
                - logs:CreateLogStream
                - logs:CreateLogGroup
                - logs:PutLogEvents
                - logs:GetLogEvents
                - logs:GetLogRecord
                - logs:GetLogGroupFields
                - logs:GetQueryResults
                - logs:DescribeLogGroups
              Resource:
                - !Sub "arn:aws:logs:${AWS::Region}:${AWS::AccountId}:log-group:airflow-${AWS::StackName}*"
            - Effect: Allow
              Action: cloudwatch:PutMetricData
              Resource: "*"
            - Effect: Allow
              Action:
                - sqs:ChangeMessageVisibility
                - sqs:DeleteMessage
                - sqs:GetQueueAttributes
                - sqs:GetQueueUrl
                - sqs:ReceiveMessage
                - sqs:SendMessage
              Resource:
                - !Sub "arn:aws:sqs:${AWS::Region}:*:airflow-celery-*"
            - Effect: Allow
              Action:
                - kms:Decrypt
                - kms:DescribeKey
                - "kms:GenerateDataKey*"
                - kms:Encrypt
              NotResource: !Sub "arn:aws:kms:*:${AWS::AccountId}:key/*"
              Condition:
                StringLike:
                  "kms:ViaService":
                    - !Sub "sqs.${AWS::Region}.amazonaws.com"
  Outputs:
    VPC:
      Description: A reference to the created VPC
      Value: !Ref VPC
  
    PublicSubnets:
      Description: A list of the public subnets
      Value: !Join [ ",", [ !Ref PublicSubnet1, !Ref PublicSubnet2 ]]
  
    PrivateSubnets:
      Description: A list of the private subnets
      Value: !Join [ ",", [ !Ref PrivateSubnet1, !Ref PrivateSubnet2 ]]
  
    PublicSubnet1:
      Description: A reference to the public subnet in the 1st Availability Zone
      Value: !Ref PublicSubnet1
  
    PublicSubnet2:
      Description: A reference to the public subnet in the 2nd Availability Zone
      Value: !Ref PublicSubnet2
  
    PrivateSubnet1:
      Description: A reference to the private subnet in the 1st Availability Zone
      Value: !Ref PrivateSubnet1
  
    PrivateSubnet2:
      Description: A reference to the private subnet in the 2nd Availability Zone
      Value: !Ref PrivateSubnet2
  
    SecurityGroupIngress:
      Description: Security group with self-referencing inbound rule
      Value: !Ref SecurityGroupIngress
  
    MwaaApacheAirflowUI:
      Description: MWAA Environment
      Value: !Sub  "https://${MwaaEnvironment.WebserverUrl}"
  ```

## Fase due: creare lo stack utilizzando il AWS CLI
<a name="quick-start-createstack"></a>

1. Nel prompt dei comandi, accedi alla directory in cui `mwaa-public-network.yml` è memorizzato. Ad esempio:

   ```
   cd mwaaproject
   ```

1. Usa il [https://docs.aws.amazon.com/cli/latest/reference/cloudformation/create-stack.html](https://docs.aws.amazon.com/cli/latest/reference/cloudformation/create-stack.html)comando per creare lo stack usando. AWS CLI

   ```
   aws cloudformation create-stack --stack-name mwaa-environment-public-network --template-body file://mwaa-public-network.yml --capabilities CAPABILITY_IAM
   ```
**Nota**  
Sono necessari più di 30 minuti per creare l'infrastruttura Amazon VPC, il bucket Amazon S3 e l'ambiente Amazon MWAA.

## Fase tre: caricare un DAG su Amazon S3 ed eseguirlo nell'interfaccia utente di Apache Airflow
<a name="quick-start-upload-dag"></a>

1. Copia il contenuto del `tutorial.py` file per l'[ultima versione supportata di Apache Airflow](https://airflow.apache.org/docs/apache-airflow/2.2.2/tutorial.html) e salva localmente come. `tutorial.py`

1. Nel prompt dei comandi, accedi alla directory in cui `tutorial.py` è memorizzato. Ad esempio:

   ```
   cd mwaaproject
   ```

1. Usa il seguente comando per elencare tutti i tuoi bucket Amazon S3.

   ```
   aws s3 ls
   ```

1. Usa il seguente comando per elencare i file e le cartelle nel bucket Amazon S3 per il tuo ambiente.

   ```
   aws s3 ls s3://YOUR_S3_BUCKET_NAME
   ```

1. Usa lo script seguente per caricare il `tutorial.py` file nella tua `dags` cartella. Sostituisci il valore del campione in*amzn-s3-demo-bucket*.

   ```
   aws s3 cp tutorial.py s3://amzn-s3-demo-bucket/dags/
   ```

1. Apri la pagina [Ambienti](https://console.aws.amazon.com/mwaa/home#/environments) sulla console Amazon MWAA.

1. Scegli un ambiente.

1. Scegli **Open Airflow UI**.

1. **Nell'interfaccia utente di Apache Airflow, dall'elenco di quelli DAGs disponibili, scegli il tutorial DAG.**

1. Nella pagina dei dettagli del DAG, scegli l'interruttore **Pause/Unpause DAG accanto al nome del DAG per riattivare il DAG**.

1. **Scegliete Trigger DAG.**

## Fase quattro: accedere ai log in Logs CloudWatch
<a name="quick-start-logs"></a>

Puoi accedere ai log di Apache Airflow nella console per tutti CloudWatch i log di Apache Airflow attivati dallo stack. CloudFormation *La sezione seguente spiega come accedere ai log per il gruppo di log del server web Airflow.*

1. Apri la pagina [Ambienti](https://console.aws.amazon.com/mwaa/home#/environments) sulla console Amazon MWAA.

1. Scegli un ambiente.

1. Scegli il **gruppo di log del server web Airflow** nel riquadro **Monitoraggio**.

1. Scegli il `webserver_console_ip` log in **Log** Streams.

## Fasi successive
<a name="quick-start-next-up"></a>
+ Scopri di più su come caricare DAGs, specificare le dipendenze Python in a `requirements.txt` e i plugin personalizzati in a in. `plugins.zip` [Lavorare con DAGs Amazon MWAA](working-dags.md)
+ Scopri di più sulle best practice che consigliamo per ottimizzare le prestazioni del tuo ambiente. [Ottimizzazione delle prestazioni per Apache Airflow su Amazon MWAA](best-practices-tuning.md)
+ Crea una dashboard di monitoraggio per il tuo ambiente in[Pannelli di controllo e allarmi su Amazon MWAA](monitoring-dashboard.md).
+ Esegui alcuni esempi di codice DAG in[Esempi di codice per Amazon Managed Workflows for Apache Airflow](sample-code.md).