

Sono disponibili altri esempi AWS SDK nel repository [AWS Doc SDK](https://github.com/awsdocs/aws-doc-sdk-examples) Examples. GitHub 

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à.

# Azioni per l'utilizzo di Resource Groups AWS SDKs
<a name="resource-groups_code_examples_actions"></a>

I seguenti esempi di codice mostrano come eseguire singole azioni di Resource Groups con AWS SDKs. Ogni esempio include un collegamento a GitHub, dove è possibile trovare le istruzioni per la configurazione e l'esecuzione del codice. 

 Gli esempi seguenti includono solo le azioni più comunemente utilizzate. Per un elenco completo, consulta la [documentazione di riferimento dell’API AWS Resource Groups](https://docs.aws.amazon.com/ARG/latest/APIReference/Welcome.html). 

**Topics**
+ [`CreateGroup`](resource-groups_example_resource-groups_CreateGroup_section.md)
+ [`DeleteGroup`](resource-groups_example_resource-groups_DeleteGroup_section.md)
+ [`GetGroup`](resource-groups_example_resource-groups_GetGroup_section.md)
+ [`GetGroupQuery`](resource-groups_example_resource-groups_GetGroupQuery_section.md)
+ [`GetTags`](resource-groups_example_resource-groups_GetTags_section.md)
+ [`ListGroupResources`](resource-groups_example_resource-groups_ListGroupResources_section.md)
+ [`ListGroups`](resource-groups_example_resource-groups_ListGroups_section.md)
+ [`SearchResources`](resource-groups_example_resource-groups_SearchResources_section.md)
+ [`Tag`](resource-groups_example_resource-groups_Tag_section.md)
+ [`Untag`](resource-groups_example_resource-groups_Untag_section.md)
+ [`UpdateGroup`](resource-groups_example_resource-groups_UpdateGroup_section.md)
+ [`UpdateGroupQuery`](resource-groups_example_resource-groups_UpdateGroupQuery_section.md)

# Utilizzare `CreateGroup` con una CLI
<a name="resource-groups_example_resource-groups_CreateGroup_section"></a>

Gli esempi di codice seguenti mostrano come utilizzare `CreateGroup`.

------
#### [ CLI ]

**AWS CLI**  
**Esempio 1: come creare un gruppo di risorse basato su tag.**  
L’esempio `create-group` seguente crea un gruppo di risorse basato su tag di istanze Amazon EC2 nella Regione corrente. Si basa su una query relativa alle risorse taggate con la chiave `Name` e il valore `WebServers`. Il nome del gruppo è `tbq-WebServer`. La query si trova in un file JSON separato che viene passato al comando.  

```
aws resource-groups create-group \
    --name tbq-WebServer \
    --resource-query file://query.json
```
Contenuto di `query.json`:  

```
{
    "Type": "TAG_FILTERS_1_0",
    "Query": "{\"ResourceTypeFilters\":[\"AWS::EC2::Instance\"],\"TagFilters\":[{\"Key\":\"Name\", \"Values\":[\"WebServers\"]}]}"
}
```
Output:  

```
{
    "Group": {
        "GroupArn": "arn:aws:resource-groups:us-west-2:123456789012:group/tbq-WebServer",
        "Name": "tbq-WebServer"
    },
    "ResourceQuery": {
        "Type": "TAG_FILTERS_1_0",
        "Query": "{\"ResourceTypeFilters\":[\"AWS::EC2::Instance\"],\"TagFilters\":[{\"Key\":\"Name\", \"Values\":[\"WebServers\"]}]}"
    }
}
```
**Esempio 2: creare un gruppo di risorse basato CloudFormation sullo stack**  
L'`create-group`esempio seguente crea un gruppo di risorse AWS CloudFormation basato sullo stack denominato. `sampleCFNstackgroup` La query include tutte le risorse nello CloudFormation stack specificato supportate da AWS Resource Groups.  

```
aws resource-groups create-group \
    --name cbq-CFNstackgroup \
    --resource-query file://query.json
```
Contenuto di `query.json`:  

```
{
    "Type": "CLOUDFORMATION_STACK_1_0",
    "Query": "{\"ResourceTypeFilters\":[\"AWS::AllSupported\"],\"StackIdentifier\":\"arn:aws:cloudformation:us-west-2:123456789012:stack/MyCFNStack/1415z9z0-z39z-11z8-97z5-500z212zz6fz\"}"
}
```
Output:  

```
{
    "Group": {
        "GroupArn": "arn:aws:resource-groups:us-west-2:123456789012:group/cbq-CFNstackgroup",
        "Name": "cbq-CFNstackgroup"
    },
    "ResourceQuery": {
        "Type": "CLOUDFORMATION_STACK_1_0",
        "Query": "{\"ResourceTypeFilters\":[\"AWS::AllSupported\"],\"StackIdentifier\":\"arn:aws:cloudformation:us-east-2:123456789012:stack/MyCFNStack/1415z9z0-z39z-11z8-97z5-500z212zz6fz\"}"}'
    }
}
```
Per ulteriori informazioni, consulta [Creazione di gruppi](https://docs.aws.amazon.com/ARG/latest/userguide/gettingstarted-query.html) nella *Guida per l’utente di Gruppi di risorse AWS *.  
+  Per i dettagli sull'API, vedere [CreateGroup](https://awscli.amazonaws.com/v2/documentation/api/latest/reference/resource-groups/create-group.html)in *AWS CLI Command Reference.* 

------
#### [ PowerShell ]

**Strumenti per PowerShell V4**  
**Esempio 1: Questo esempio crea un nuovo gruppo di AWS risorse Resource Groups basato su tag denominato TestPowerShellGroup. Il gruppo include istanze Amazon EC2 nella Regione corrente contrassegnate con la chiave di tag “Name” e il valore di tag “test2”. Il comando restituisce la query e il tipo di gruppo e i risultati dell’operazione.**  

```
$ResourceQuery = New-Object -TypeName Amazon.ResourceGroups.Model.ResourceQuery
$ResourceQuery.Type = "TAG_FILTERS_1_0"
$ResourceQuery.Query = '{"ResourceTypeFilters":["AWS::EC2::Instance"],"TagFilters":[{"Key":"Name","Values":["test2"]}]}'
$ResourceQuery

New-RGGroup -Name TestPowerShellGroup -ResourceQuery $ResourceQuery -Description "Test resource group."
```
**Output:**  

```
Query                                                                                           Type           
-----                                                                                           ----           
{"ResourceTypeFilters":["AWS::EC2::Instance"],"TagFilters":[{"Key":"Name","Values":["test2"]}]} TAG_FILTERS_1_0

LoggedAt         : 11/20/2018 2:40:59 PM
Group            : Amazon.ResourceGroups.Model.Group
ResourceQuery    : Amazon.ResourceGroups.Model.ResourceQuery
Tags             : {}
ResponseMetadata : Amazon.Runtime.ResponseMetadata
ContentLength    : 338
HttpStatusCode   : OK
```
+  Per i dettagli sull'API, vedere [CreateGroup](https://docs.aws.amazon.com/powershell/v4/reference)in *AWS Strumenti per PowerShell Cmdlet Reference (*V4). 

**Strumenti per V5 PowerShell **  
**Esempio 1: Questo esempio crea un nuovo gruppo di AWS risorse Resource Groups basato su tag denominato TestPowerShellGroup. Il gruppo include istanze Amazon EC2 nella Regione corrente contrassegnate con la chiave di tag “Name” e il valore di tag “test2”. Il comando restituisce la query e il tipo di gruppo e i risultati dell’operazione.**  

```
$ResourceQuery = New-Object -TypeName Amazon.ResourceGroups.Model.ResourceQuery
$ResourceQuery.Type = "TAG_FILTERS_1_0"
$ResourceQuery.Query = '{"ResourceTypeFilters":["AWS::EC2::Instance"],"TagFilters":[{"Key":"Name","Values":["test2"]}]}'
$ResourceQuery

New-RGGroup -Name TestPowerShellGroup -ResourceQuery $ResourceQuery -Description "Test resource group."
```
**Output:**  

```
Query                                                                                           Type           
-----                                                                                           ----           
{"ResourceTypeFilters":["AWS::EC2::Instance"],"TagFilters":[{"Key":"Name","Values":["test2"]}]} TAG_FILTERS_1_0

LoggedAt         : 11/20/2018 2:40:59 PM
Group            : Amazon.ResourceGroups.Model.Group
ResourceQuery    : Amazon.ResourceGroups.Model.ResourceQuery
Tags             : {}
ResponseMetadata : Amazon.Runtime.ResponseMetadata
ContentLength    : 338
HttpStatusCode   : OK
```
+  Per i dettagli sull'API, vedere [CreateGroup](https://docs.aws.amazon.com/powershell/v5/reference)in *AWS Strumenti per PowerShell Cmdlet Reference (*V5). 

------

# Utilizzare `DeleteGroup` con una CLI
<a name="resource-groups_example_resource-groups_DeleteGroup_section"></a>

Gli esempi di codice seguenti mostrano come utilizzare `DeleteGroup`.

------
#### [ CLI ]

**AWS CLI**  
**Come aggiornare la descrizione di un gruppo di risorse**  
L’esempio `delete-group` seguente aggiorna il gruppo di risorse specificato.  

```
aws resource-groups delete-group \
    --group-name tbq-WebServer
```
Output:  

```
{
    "Group": {
        "GroupArn": "arn:aws:resource-groups:us-west-2:1234567890:group/tbq-WebServer",
        "Name": "tbq-WebServer"
    }
}
```
Per ulteriori informazioni, consulta [Eliminazione di gruppi](https://docs.aws.amazon.com/ARG/latest/userguide/deleting-resource-groups.html) nella *Guida per l’utente di Gruppi di risorse AWS *.  
+  Per i dettagli sull'API, consulta [DeleteGroup AWS CLI](https://awscli.amazonaws.com/v2/documentation/api/latest/reference/resource-groups/delete-group.html)*Command Reference.* 

------
#### [ PowerShell ]

**Strumenti per PowerShell V4**  
**Esempio 1: questo esempio rimuove il gruppo di risorse denominato**  

```
Remove-RGGroup -GroupName non-tag-cfn-elbv2
```
**Output:**  

```
Confirm
Are you sure you want to perform this action?
Performing the operation "Remove-RGGroup (DeleteGroup)" on target "non-tag-cfn-elbv2".
[Y] Yes  [A] Yes to All  [N] No  [L] No to All  [S] Suspend  [?] Help (default is "Y"): Y

Description GroupArn                                                               Name
----------- --------                                                               ----
            arn:aws:resource-groups:eu-west-1:123456789012:group/non-tag-cfn-elbv2 non-tag-cfn-elbv2
```
+  Per i dettagli sull'API, vedere [DeleteGroup](https://docs.aws.amazon.com/powershell/v4/reference)in *AWS Strumenti per PowerShell Cmdlet Reference (*V4). 

**Strumenti per V5 PowerShell **  
**Esempio 1: questo esempio rimuove il gruppo di risorse denominato**  

```
Remove-RGGroup -GroupName non-tag-cfn-elbv2
```
**Output:**  

```
Confirm
Are you sure you want to perform this action?
Performing the operation "Remove-RGGroup (DeleteGroup)" on target "non-tag-cfn-elbv2".
[Y] Yes  [A] Yes to All  [N] No  [L] No to All  [S] Suspend  [?] Help (default is "Y"): Y

Description GroupArn                                                               Name
----------- --------                                                               ----
            arn:aws:resource-groups:eu-west-1:123456789012:group/non-tag-cfn-elbv2 non-tag-cfn-elbv2
```
+  Per i dettagli sull'API, vedere [DeleteGroup](https://docs.aws.amazon.com/powershell/v5/reference)in *AWS Strumenti per PowerShell Cmdlet Reference (*V5). 

------

# Utilizzare `GetGroup` con una CLI
<a name="resource-groups_example_resource-groups_GetGroup_section"></a>

Gli esempi di codice seguenti mostrano come utilizzare `GetGroup`.

------
#### [ CLI ]

**AWS CLI**  
**Come ottenere informazioni su un gruppo di risorse**  
L’esempio `get-group` seguente visualizza i dettagli relativi al gruppo di risorse specificato. Per ottenere la query associata al gruppo, utilizza `get-group-query`.  

```
aws resource-groups get-group \
    --group-name tbq-WebServer
```
Output:  

```
{
    "Group": {
        "GroupArn": "arn:aws:resource-groups:us-west-2:123456789012:group/tbq-WebServer",
        "Name": "tbq-WebServer",
        "Description": "A tag-based query resource group of WebServers."
    }
}
```
+  Per i dettagli sull'API, consulta [GetGroup AWS CLI](https://awscli.amazonaws.com/v2/documentation/api/latest/reference/resource-groups/get-group.html)*Command Reference.* 

------
#### [ PowerShell ]

**Strumenti per PowerShell V4**  
**Esempio 1: questo esempio recupera il gruppo di risorse in base al nome del gruppo**  

```
Get-RGGroup -GroupName auto-no
```
**Output:**  

```
Description GroupArn                                                     Name
----------- --------                                                     ----
            arn:aws:resource-groups:eu-west-1:123456789012:group/auto-no auto-no
```
+  Per i dettagli sull'API, vedere [GetGroup](https://docs.aws.amazon.com/powershell/v4/reference)in *AWS Strumenti per PowerShell Cmdlet Reference (*V4). 

**Strumenti per V5 PowerShell **  
**Esempio 1: questo esempio recupera il gruppo di risorse in base al nome del gruppo**  

```
Get-RGGroup -GroupName auto-no
```
**Output:**  

```
Description GroupArn                                                     Name
----------- --------                                                     ----
            arn:aws:resource-groups:eu-west-1:123456789012:group/auto-no auto-no
```
+  Per i dettagli sull'API, vedere [GetGroup](https://docs.aws.amazon.com/powershell/v5/reference)in *AWS Strumenti per PowerShell Cmdlet Reference (*V5). 

------

# Utilizzare `GetGroupQuery` con una CLI
<a name="resource-groups_example_resource-groups_GetGroupQuery_section"></a>

Gli esempi di codice seguenti mostrano come utilizzare `GetGroupQuery`.

------
#### [ CLI ]

**AWS CLI**  
**Come ottenere la query associata a un gruppo di risorse**  
L’esempio `get-group-query` seguente visualizza la query associata al gruppo di risorse specificato.  

```
aws resource-groups get-group-query \
    --group-name tbq-WebServer
```
Output:  

```
{
    "GroupQuery": {
        "GroupName": "tbq-WebServer",
        "ResourceQuery": {
            "Type": "TAG_FILTERS_1_0",
            "Query": "{\"ResourceTypeFilters\":[\"AWS::EC2::Instance\"],\"TagFilters\":[{\"Key\":\"Name\", \"Values\":[\"WebServers\"]}]}"
        }
    }
}
```
+  Per i dettagli sull'API, consulta [GetGroupQuery AWS CLI](https://awscli.amazonaws.com/v2/documentation/api/latest/reference/resource-groups/get-group-query.html)*Command Reference.* 

------
#### [ PowerShell ]

**Strumenti per PowerShell V4**  
**Esempio 1: questo esempio recupera la query di risorse per il gruppo di risorse specificato**  

```
Get-RGGroupQuery -GroupName auto-no | Select-Object -ExpandProperty ResourceQuery
```
**Output:**  

```
Query                                                                                        Type
-----                                                                                        ----
{"ResourceTypeFilters":["AWS::EC2::Instance"],"TagFilters":[{"Key":"auto","Values":["no"]}]} TAG_FILTERS_1_0
```
+  Per i dettagli sull'API, vedere [GetGroupQuery](https://docs.aws.amazon.com/powershell/v4/reference)in *AWS Strumenti per PowerShell Cmdlet Reference (*V4). 

**Strumenti per V5 PowerShell **  
**Esempio 1: questo esempio recupera la query di risorse per il gruppo di risorse specificato**  

```
Get-RGGroupQuery -GroupName auto-no | Select-Object -ExpandProperty ResourceQuery
```
**Output:**  

```
Query                                                                                        Type
-----                                                                                        ----
{"ResourceTypeFilters":["AWS::EC2::Instance"],"TagFilters":[{"Key":"auto","Values":["no"]}]} TAG_FILTERS_1_0
```
+  Per i dettagli sull'API, vedere [GetGroupQuery](https://docs.aws.amazon.com/powershell/v5/reference)in *AWS Strumenti per PowerShell Cmdlet Reference (*V5). 

------

# Utilizzare `GetTags` con una CLI
<a name="resource-groups_example_resource-groups_GetTags_section"></a>

Gli esempi di codice seguenti mostrano come utilizzare `GetTags`.

------
#### [ CLI ]

**AWS CLI**  
**Come recuperare i tag associati a un gruppo di risorse**  
L’esempio `get-tags` seguente visualizza le coppie di chiavi di tag e valori associate al gruppo di risorse specificato (il gruppo stesso e non i relativi membri).  

```
aws resource-groups get-tags \
    --arn arn:aws:resource-groups:us-west-2:123456789012:group/tbq-WebServer
```
Output:  

```
{
    "Arn": "arn:aws:resource-groups:us-west-2:123456789012:group/tbq-WebServer",
    "Tags": {
        "QueryType": "tags",
        "QueryResources": "ec2-instances"
    }
}
```
+  Per i dettagli sull'API, consulta [GetTags AWS CLI](https://awscli.amazonaws.com/v2/documentation/api/latest/reference/resource-groups/get-tags.html)*Command Reference.* 

------
#### [ PowerShell ]

**Strumenti per PowerShell V4**  
**Esempio 1: questo esempio elenca i tag per l’ARN del gruppo di risorse specificato**  

```
Get-RGResourceTag -Arn arn:aws:resource-groups:eu-west-1:123456789012:group/workboxes
```
**Output:**  

```
Key       Value
---       -----
Instances workboxes
```
+  Per i dettagli sull'API, vedere [GetTags](https://docs.aws.amazon.com/powershell/v4/reference)in *AWS Strumenti per PowerShell Cmdlet Reference (*V4). 

**Strumenti per V5 PowerShell **  
**Esempio 1: questo esempio elenca i tag per l’ARN del gruppo di risorse specificato**  

```
Get-RGResourceTag -Arn arn:aws:resource-groups:eu-west-1:123456789012:group/workboxes
```
**Output:**  

```
Key       Value
---       -----
Instances workboxes
```
+  Per i dettagli sull'API, vedere [GetTags](https://docs.aws.amazon.com/powershell/v5/reference)in *AWS Strumenti per PowerShell Cmdlet Reference (*V5). 

------

# Utilizzare `ListGroupResources` con una CLI
<a name="resource-groups_example_resource-groups_ListGroupResources_section"></a>

Gli esempi di codice seguenti mostrano come utilizzare `ListGroupResources`.

------
#### [ CLI ]

**AWS CLI**  
**Come elencare tutte le risorse in un gruppo di risorse**  
Esempio 1: l’esempio `list-resource-groups` seguente elenca tutte le risorse appartenenti gruppo di risorse specificato.  

```
aws resource-groups list-group-resources \
    --group-name tbq-WebServer
```
Output:  

```
{
    "ResourceIdentifiers": [
        {
            "ResourceArn": "arn:aws:ec2:us-west-2:123456789012:instance/i-09f77fa38c12345ab",
            "ResourceType": "AWS::EC2::Instance"
        }
    ]
}
```
Esempio 2: l’esempio seguente elenca tutte le risorse del gruppo che hanno il parametro “resource-type” con il valore “AWS::EC2::Instance”.  
aws resource-groups list-group-resources --group-name tbq- --filters Nome=tipo-risorsa, Values=: :EC2: :Instance WebServer AWS  
+  Per i dettagli sull'API, consulta [ListGroupResources AWS CLI](https://awscli.amazonaws.com/v2/documentation/api/latest/reference/resource-groups/list-group-resources.html)*Command Reference.* 

------
#### [ PowerShell ]

**Strumenti per PowerShell V4**  
**Esempio 1: questo esempio elenca le risorse del gruppo filtrate in base al tipo di risorsa**  

```
Get-RGGroupResourceList -Filter @{Name="resource-type";Values="AWS::EC2::Instance"} -GroupName auto-yes | Select-Object -ExpandProperty ResourceIdentifiers
```
**Output:**  

```
ResourceArn                                                     ResourceType
-----------                                                     ------------
arn:aws:ec2:eu-west-1:123456789012:instance/i-0123bc45b567890e1 AWS::EC2::Instance
arn:aws:ec2:eu-west-1:123456789012:instance/i-0a1caf2345f67d8dc AWS::EC2::Instance
arn:aws:ec2:eu-west-1:123456789012:instance/i-012e3cb4df567e8aa AWS::EC2::Instance
arn:aws:ec2:eu-west-1:123456789012:instance/i-0fd12dd3456789012 AWS::EC2::Instance
```
+  Per i dettagli sull'API, vedere [ListGroupResources](https://docs.aws.amazon.com/powershell/v4/reference)in *AWS Strumenti per PowerShell Cmdlet Reference (*V4). 

**Strumenti per V5 PowerShell **  
**Esempio 1: questo esempio elenca le risorse del gruppo filtrate in base al tipo di risorsa**  

```
Get-RGGroupResourceList -Filter @{Name="resource-type";Values="AWS::EC2::Instance"} -GroupName auto-yes | Select-Object -ExpandProperty ResourceIdentifiers
```
**Output:**  

```
ResourceArn                                                     ResourceType
-----------                                                     ------------
arn:aws:ec2:eu-west-1:123456789012:instance/i-0123bc45b567890e1 AWS::EC2::Instance
arn:aws:ec2:eu-west-1:123456789012:instance/i-0a1caf2345f67d8dc AWS::EC2::Instance
arn:aws:ec2:eu-west-1:123456789012:instance/i-012e3cb4df567e8aa AWS::EC2::Instance
arn:aws:ec2:eu-west-1:123456789012:instance/i-0fd12dd3456789012 AWS::EC2::Instance
```
+  Per i dettagli sull'API, vedere [ListGroupResources](https://docs.aws.amazon.com/powershell/v5/reference)in *AWS Strumenti per PowerShell Cmdlet Reference (*V5). 

------

# Utilizzare `ListGroups` con una CLI
<a name="resource-groups_example_resource-groups_ListGroups_section"></a>

Gli esempi di codice seguenti mostrano come utilizzare `ListGroups`.

------
#### [ CLI ]

**AWS CLI**  
**Come elencare i gruppi di risorse disponibili**  
L’esempio `list-groups` seguente visualizza un elenco di tutti i gruppi di risorse.  

```
aws resource-groups list-groups
```
Output:  

```
{
    "GroupIdentifiers": [
        {
            "GroupName": "tbq-WebServer",
            "GroupArn": "arn:aws:resource-groups:us-west-2:123456789012:group/tbq-WebServer3"
        },
        {
            "GroupName": "cbq-CFNStackQuery",
            "GroupArn": "arn:aws:resource-groups:us-west-2:123456789012:group/cbq-CFNStackQuery"
        }
    ],
    "Groups": [
        {
            "GroupArn": "arn:aws:resource-groups:us-west-2:123456789012:group/tbq-WebServer",
            "Name": "tbq-WebServer"
        },
        {
            "GroupArn": "arn:aws:resource-groups:us-west-2:123456789012:group/cbq-CFNStackQuery",
            "Name": "cbq-CFNStackQuery"
        }
    ]
}
```
+  Per i dettagli sull'API, consulta [ListGroups AWS CLI](https://awscli.amazonaws.com/v2/documentation/api/latest/reference/resource-groups/list-groups.html)*Command Reference.* 

------
#### [ PowerShell ]

**Strumenti per PowerShell V4**  
**Esempio 1: questo esempio elenca i gruppi di risorse già creati.**  

```
Get-RGGroupList
```
**Output:**  

```
GroupArn                                                                  GroupName
--------                                                                  ---------
arn:aws:resource-groups:eu-west-1:123456789012:group/auto-no              auto-no
arn:aws:resource-groups:eu-west-1:123456789012:group/auto-yes             auto-yes
arn:aws:resource-groups:eu-west-1:123456789012:group/build600             build600
```
+  Per i dettagli sull'API, vedere [ListGroups](https://docs.aws.amazon.com/powershell/v4/reference)in *AWS Strumenti per PowerShell Cmdlet Reference (*V4). 

**Strumenti per V5 PowerShell **  
**Esempio 1: questo esempio elenca i gruppi di risorse già creati.**  

```
Get-RGGroupList
```
**Output:**  

```
GroupArn                                                                  GroupName
--------                                                                  ---------
arn:aws:resource-groups:eu-west-1:123456789012:group/auto-no              auto-no
arn:aws:resource-groups:eu-west-1:123456789012:group/auto-yes             auto-yes
arn:aws:resource-groups:eu-west-1:123456789012:group/build600             build600
```
+  Per i dettagli sull'API, vedere [ListGroups](https://docs.aws.amazon.com/powershell/v5/reference)in *AWS Strumenti per PowerShell Cmdlet Reference (*V5). 

------

# Utilizzare `SearchResources` con una CLI
<a name="resource-groups_example_resource-groups_SearchResources_section"></a>

Gli esempi di codice seguenti mostrano come utilizzare `SearchResources`.

------
#### [ CLI ]

**AWS CLI**  
**Come trovare le risorse che corrispondono a una query**  
L'`search-resources`esempio seguente recupera un elenco di tutte le AWS risorse che corrispondono alla query specificata.  

```
aws resource-groups search-resources \
    --resource-query file://query.json
```
Contenuto di `query.json`:  

```
{
    "Type": "TAG_FILTERS_1_0",
    "Query": "{\"ResourceTypeFilters\":[\"AWS::EC2::Instance\"],\"TagFilters\":[{\"Key\":\"Patch Group\", \"Values\":[\"Dev\"]}]}"
}
```
Output:  

```
{
    "ResourceIdentifiers": [
        {
            "ResourceArn": "arn:aws:ec2:us-west-2:123456789012:instance/i-01a23bc45d67890ef",
            "ResourceType": "AWS::EC2::Instance"
        }
    ]
}
```
+  Per i dettagli sull'API, vedere [SearchResources](https://awscli.amazonaws.com/v2/documentation/api/latest/reference/resource-groups/search-resources.html)in *AWS CLI Command Reference.* 

------
#### [ PowerShell ]

**Strumenti per PowerShell V4**  
**Esempio 1: questo esempio crea un tipo di risorsa ad ResourceQuery esempio con filtri di tag e trova risorse.**  

```
$query = [Amazon.ResourceGroups.Model.ResourceQuery]::new()
$query.Type = [Amazon.ResourceGroups.QueryType]::TAG_FILTERS_1_0
$query.Query = ConvertTo-Json -Compress -Depth 4 -InputObject @{
  ResourceTypeFilters = @('AWS::EC2::Instance')
  TagFilters = @(@{
    Key = 'auto'
    Values = @('no')
  })
 }

Find-RGResource -ResourceQuery $query | Select-Object -ExpandProperty ResourceIdentifiers
```
**Output:**  

```
ResourceArn                                                     ResourceType
-----------                                                     ------------
arn:aws:ec2:eu-west-1:123456789012:instance/i-0123445b6cb7bd67b AWS::EC2::Instance
```
+  Per i dettagli sull'API, vedere [SearchResources](https://docs.aws.amazon.com/powershell/v4/reference)in *AWS Strumenti per PowerShell Cmdlet Reference (V4)*. 

**Strumenti per V5 PowerShell **  
**Esempio 1: questo esempio crea un tipo di risorsa ad ResourceQuery esempio con filtri di tag e trova risorse.**  

```
$query = [Amazon.ResourceGroups.Model.ResourceQuery]::new()
$query.Type = [Amazon.ResourceGroups.QueryType]::TAG_FILTERS_1_0
$query.Query = ConvertTo-Json -Compress -Depth 4 -InputObject @{
  ResourceTypeFilters = @('AWS::EC2::Instance')
  TagFilters = @(@{
    Key = 'auto'
    Values = @('no')
  })
 }

Find-RGResource -ResourceQuery $query | Select-Object -ExpandProperty ResourceIdentifiers
```
**Output:**  

```
ResourceArn                                                     ResourceType
-----------                                                     ------------
arn:aws:ec2:eu-west-1:123456789012:instance/i-0123445b6cb7bd67b AWS::EC2::Instance
```
+  Per i dettagli sull'API, vedere [SearchResources](https://docs.aws.amazon.com/powershell/v5/reference)in *AWS Strumenti per PowerShell Cmdlet Reference (V5)*. 

------

# Utilizzare `Tag` con una CLI
<a name="resource-groups_example_resource-groups_Tag_section"></a>

Gli esempi di codice seguenti mostrano come utilizzare `Tag`.

------
#### [ CLI ]

**AWS CLI**  
**Come associare un tag a un gruppo di risorse**  
L’esempio `tag` seguente collega le coppie di chiavi di tag e valori specificate al gruppo di risorse specificato (il gruppo stesso e non i relativi membri).  

```
aws resource-groups tag \
    --tags QueryType=tags,QueryResources=ec2-instances \
    --arn arn:aws:resource-groups:us-west-2:128716708097:group/tbq-WebServer
```
Output:  

```
{
    "Arn": "arn:aws:resource-groups:us-west-2:128716708097:group/tbq-WebServer",
    "Tags": {
        "QueryType": "tags",
        "QueryResources": "ec2-instances"
    }
}
```
Per ulteriori informazioni, consulta [Gestione dei tag](https://docs.aws.amazon.com/ARG/latest/userguide/tagging-resources.html) nella *Guida per l’utente di Gruppi di risorse AWS *.  
+  Per informazioni dettagliate sull’API, consulta [Tag](https://awscli.amazonaws.com/v2/documentation/api/latest/reference/resource-groups/tag.html) nella *documentazione di riferimento dei comandi della AWS CLI *. 

------
#### [ PowerShell ]

**Strumenti per PowerShell V4**  
**Esempio 1: questo esempio aggiunge la chiave di tag “Instances” con il valore “workboxes” all’ARN del gruppo di risorse specificato**  

```
Add-RGResourceTag -Tag @{Instances="workboxes"} -Arn arn:aws:resource-groups:eu-west-1:123456789012:group/workboxes
```
**Output:**  

```
Arn                                                            Tags
---                                                            ----
arn:aws:resource-groups:eu-west-1:123456789012:group/workboxes {[Instances, workboxes]}
```
+  Per informazioni dettagliate sull’API, consulta [Tag](https://docs.aws.amazon.com/powershell/v4/reference) nella *documentazione di riferimento dei cmdlet di AWS Strumenti per PowerShell (V4)*. 

**Strumenti per PowerShell V5**  
**Esempio 1: questo esempio aggiunge la chiave di tag “Instances” con il valore “workboxes” all’ARN del gruppo di risorse specificato**  

```
Add-RGResourceTag -Tag @{Instances="workboxes"} -Arn arn:aws:resource-groups:eu-west-1:123456789012:group/workboxes
```
**Output:**  

```
Arn                                                            Tags
---                                                            ----
arn:aws:resource-groups:eu-west-1:123456789012:group/workboxes {[Instances, workboxes]}
```
+  Per informazioni dettagliate sull’API, consulta [Tag](https://docs.aws.amazon.com/powershell/v5/reference) nella *documentazione di riferimento dei cmdlet di AWS Strumenti per PowerShell (V5)*. 

------

# Utilizzare `Untag` con una CLI
<a name="resource-groups_example_resource-groups_Untag_section"></a>

Gli esempi di codice seguenti mostrano come utilizzare `Untag`.

------
#### [ CLI ]

**AWS CLI**  
**Come rimuovere i tag da un gruppo di risorse**  
L’esempio `untags` seguente rimuove qualsiasi tag con la chiave specificata dal gruppo di risorse stesso e non dai relativi membri.  

```
aws resource-groups untag \
    --arn arn:aws:resource-groups:us-west-2:123456789012:group/tbq-WebServer \
    --keys QueryType
```
Output:  

```
{
    "Arn": "arn:aws:resource-groups:us-west-2:123456789012:group/tbq-WebServer",
    "Keys": [
        "QueryType"
    ]
}
```
Per ulteriori informazioni, consulta [Gestione dei tag](https://docs.aws.amazon.com/ARG/latest/userguide/tagging-resources.html) nella *Guida per l’utente di Gruppi di risorse AWS *.  
+  Per informazioni dettagliate sull’API, consulta [Untag](https://awscli.amazonaws.com/v2/documentation/api/latest/reference/resource-groups/untag.html) nella *documentazione di riferimento dei comandi della AWS CLI *. 

------
#### [ PowerShell ]

**Strumenti per PowerShell V4**  
**Esempio 1: questo esempio rimuove il tag menzionato dal gruppo di risorse**  

```
Remove-RGResourceTag -Arn arn:aws:resource-groups:eu-west-1:123456789012:group/workboxes -Key Instances
```
**Output:**  

```
Confirm
Are you sure you want to perform this action?
Performing the operation "Remove-RGResourceTag (Untag)" on target "arn:aws:resource-groups:eu-west-1:933303704102:group/workboxes".
[Y] Yes  [A] Yes to All  [N] No  [L] No to All  [S] Suspend  [?] Help (default is "Y"): Y

Arn                                                            Keys
---                                                            ----
arn:aws:resource-groups:eu-west-1:123456789012:group/workboxes {Instances}
```
+  Per informazioni dettagliate sull’API, consulta [Untag](https://docs.aws.amazon.com/powershell/v4/reference) nella *documentazione di riferimento dei cmdlet di AWS Strumenti per PowerShell (V4)*. 

**Strumenti per PowerShell V5**  
**Esempio 1: questo esempio rimuove il tag menzionato dal gruppo di risorse**  

```
Remove-RGResourceTag -Arn arn:aws:resource-groups:eu-west-1:123456789012:group/workboxes -Key Instances
```
**Output:**  

```
Confirm
Are you sure you want to perform this action?
Performing the operation "Remove-RGResourceTag (Untag)" on target "arn:aws:resource-groups:eu-west-1:933303704102:group/workboxes".
[Y] Yes  [A] Yes to All  [N] No  [L] No to All  [S] Suspend  [?] Help (default is "Y"): Y

Arn                                                            Keys
---                                                            ----
arn:aws:resource-groups:eu-west-1:123456789012:group/workboxes {Instances}
```
+  Per informazioni dettagliate sull’API, consulta [Untag](https://docs.aws.amazon.com/powershell/v5/reference) nella *documentazione di riferimento dei cmdlet di AWS Strumenti per PowerShell (V5)*. 

------

# Utilizzare `UpdateGroup` con una CLI
<a name="resource-groups_example_resource-groups_UpdateGroup_section"></a>

Gli esempi di codice seguenti mostrano come utilizzare `UpdateGroup`.

------
#### [ CLI ]

**AWS CLI**  
**Come aggiornare la descrizione di un gruppo di risorse**  
L’esempio `update-group` seguente aggiorna la descrizione del gruppo di risorse specificato.  

```
aws resource-groups update-group \
    --group-name tbq-WebServer \
    --description "Resource group for all web server resources."
```
Output:  

```
{
    "Group": {
        "GroupArn": "arn:aws:resource-groups:us-west-2:123456789012:group/tbq-WebServer",
        "Name": "tbq-WebServer"
        "Description": "Resource group for all web server resources."
    }
}
```
Per ulteriori informazioni, consulta [Aggiornamento dei gruppi](https://docs.aws.amazon.com/ARG/latest/userguide/updating-resource-groups.html) nella *Guida per l’utente di Gruppi di risorse AWS *.  
+  Per i dettagli sull'API, consulta [UpdateGroup AWS CLI](https://awscli.amazonaws.com/v2/documentation/api/latest/reference/resource-groups/update-group.html)*Command Reference.* 

------
#### [ PowerShell ]

**Strumenti per PowerShell V4**  
**Esempio 1: questo esempio aggiorna la descrizione del gruppo**  

```
Update-RGGroup -GroupName auto-yes -Description "Instances auto-remove"
```
**Output:**  

```
Description             GroupArn                                                      Name
-----------             --------                                                      ----
Instances to be cleaned arn:aws:resource-groups:eu-west-1:123456789012:group/auto-yes auto-yes
```
+  Per i dettagli sull'API, vedere [UpdateGroup](https://docs.aws.amazon.com/powershell/v4/reference)in *AWS Strumenti per PowerShell Cmdlet Reference (*V4). 

**Strumenti per V5 PowerShell **  
**Esempio 1: questo esempio aggiorna la descrizione del gruppo**  

```
Update-RGGroup -GroupName auto-yes -Description "Instances auto-remove"
```
**Output:**  

```
Description             GroupArn                                                      Name
-----------             --------                                                      ----
Instances to be cleaned arn:aws:resource-groups:eu-west-1:123456789012:group/auto-yes auto-yes
```
+  Per i dettagli sull'API, vedere [UpdateGroup](https://docs.aws.amazon.com/powershell/v5/reference)in *AWS Strumenti per PowerShell Cmdlet Reference (*V5). 

------

# Utilizzare `UpdateGroupQuery` con una CLI
<a name="resource-groups_example_resource-groups_UpdateGroupQuery_section"></a>

Gli esempi di codice seguenti mostrano come utilizzare `UpdateGroupQuery`.

------
#### [ CLI ]

**AWS CLI**  
**Esempio 1: come aggiornare la query per un gruppo di risorse basato su tag.**  
L’esempio `update-group-query` seguente aggiorna la query associata al gruppo di risorse basato su tag specificato.  

```
aws resource-groups update-group-query \
    --group-name tbq-WebServer \
    --resource-query '{"Type":"TAG_FILTERS_1_0", "Query":"{\"ResourceTypeFilters\":[\"AWS::EC2::Instance\"],\"TagFilters\":[{\"Key\":\"Name\", \"Values\":[\"WebServers\"]}]}"}'
```
Output:  

```
{
    "Group": {
        "GroupArn": "arn:aws:resource-groups:us-east-2:123456789012:group/tbq-WebServer",
        "Name": "tbq-WebServer"
    },
    "ResourceQuery": {
        "Type": "TAG_FILTERS_1_0",
        "Query": "{\"ResourceTypeFilters\":[\"AWS::EC2::Instance\"],\"TagFilters\":[{\"Key\":\"Name\", \"Values\":[\"WebServers\"]}]}"
    }
}
```
Per ulteriori informazioni, consulta [Aggiornamento dei gruppi](https://docs.aws.amazon.com/ARG/latest/userguide/updating-resource-groups.html) nella *Guida per l’utente di Gruppi di risorse AWS *.  
**Esempio 2: aggiornare la query per un gruppo di risorse basato CloudFormation sullo stack**  
L'`update-group-query`esempio seguente aggiorna la query allegata al gruppo di risorse basato sullo AWS CloudFormation stack specificato.  

```
aws resource-groups update-group-query \
    --group-name cbq-CFNstackgroup \
    --resource-query '{"Type": "CLOUDFORMATION_STACK_1_0", "Query": "{\"ResourceTypeFilters\":[\"AWS::AllSupported\"],\"StackIdentifier\":\"arn:aws:cloudformation:us-west-2:123456789012:stack/MyCFNStack/1415z9z0-z39z-11z8-97z5-500z212zz6fz\"}"}'
```
Output:  

```
{
    "Group": {
        "GroupArn": "arn:aws:resource-groups:us-west-2:123456789012:group/cbq-CFNstackgroup",
        "Name": "cbq-CFNstackgroup"
    },
    "ResourceQuery": {
        "Type": "CLOUDFORMATION_STACK_1_0",
        "Query": "{\"ResourceTypeFilters\":[\"AWS::AllSupported\"],\"StackIdentifier\":\"arn:aws:cloudformation:us-west-2:123456789012:stack/MyCFNStack/1415z9z0-z39z-11z8-97z5-500z212zz6fz\"}"
    }
}
```
Per ulteriori informazioni, consulta [Aggiornamento dei gruppi](https://docs.aws.amazon.com/ARG/latest/userguide/updating-resource-groups.html) nella *Guida per l’utente di Gruppi di risorse AWS *.  
+  Per i dettagli sull'API, vedere [UpdateGroupQuery](https://awscli.amazonaws.com/v2/documentation/api/latest/reference/resource-groups/update-group-query.html)in *AWS CLI Command Reference*. 

------
#### [ PowerShell ]

**Strumenti per PowerShell V4**  
**Esempio 1: questo esempio crea un oggetto query e aggiorna la query per il gruppo.**  

```
$query = [Amazon.ResourceGroups.Model.ResourceQuery]::new()
$query.Type = [Amazon.ResourceGroups.QueryType]::TAG_FILTERS_1_0
$query.Query = @{
  ResourceTypeFilters = @('AWS::EC2::Instance')
  TagFilters = @(@{
  Key='Environment'
  Values='Build600.11'
  })
} | ConvertTo-Json -Compress -Depth 4

Update-RGGroupQuery -GroupName build600 -ResourceQuery $query
```
**Output:**  

```
GroupName ResourceQuery
--------- -------------
build600  Amazon.ResourceGroups.Model.ResourceQuery
```
+  Per i dettagli sull'API, vedere [UpdateGroupQuery](https://docs.aws.amazon.com/powershell/v4/reference)in *AWS Strumenti per PowerShell Cmdlet Reference (*V4). 

**Strumenti per V5 PowerShell **  
**Esempio 1: questo esempio crea un oggetto query e aggiorna la query per il gruppo.**  

```
$query = [Amazon.ResourceGroups.Model.ResourceQuery]::new()
$query.Type = [Amazon.ResourceGroups.QueryType]::TAG_FILTERS_1_0
$query.Query = @{
  ResourceTypeFilters = @('AWS::EC2::Instance')
  TagFilters = @(@{
  Key='Environment'
  Values='Build600.11'
  })
} | ConvertTo-Json -Compress -Depth 4

Update-RGGroupQuery -GroupName build600 -ResourceQuery $query
```
**Output:**  

```
GroupName ResourceQuery
--------- -------------
build600  Amazon.ResourceGroups.Model.ResourceQuery
```
+  Per i dettagli sull'API, vedere [UpdateGroupQuery](https://docs.aws.amazon.com/powershell/v5/reference)in *AWS Strumenti per PowerShell Cmdlet Reference (*V5). 

------