By using AWS re:Post, you agree to the Terms of Use

AWS CLI needs to be converted to PowerShell

0

Below is the AWS CLI that needs to be converted to PowerShell

$export_AWS = aws configservice select-aggregate-resource-config --expression "SELECT accountId,awsRegion,arn,resourceId WHERE resourceType = 'AWS::EC2::Instance'" --configuration-aggregator-name XXXXXXXXX

1 Answer
0

You will find the documentation for the PowerShell CmdLets for AWS here: https://docs.aws.amazon.com/powershell/latest/reference/index.html

The appropriate CmdLet counterpart for your cli command is Select-CFGServiceAggregateResourceConfig and the command would look like this:

Select-CFGAggregateResourceConfig -ConfigurationAggregatorName XXXXXXXXX -Expression "SELECT accountId,awsRegion,arn,resourceId WHERE resourceType = 'AWS::EC2::Instance'"
EXPERT
answered 21 days ago
  • Your kind response is greatly appreciated. Using AWS CLI, I am able to obtain the response, however when I attempt to execute the command that you provided, I receive the following error message. Could you please let me know if there is anything else I need to do

    Select-CFGAggregateResourceConfig : The configuration aggregator does not exist. Check the configuration aggregator name and try again. At line:1 char:1

    • Select-CFGAggregateResourceConfig -ConfigurationAggregatorName ...
    •   + CategoryInfo          : InvalidOperation: (Amazon.PowerShe...rceConfigCmdlet:SelectCFGAggregateResourceConfigCmdlet) [Select-CFGAggregateResourceConfig], InvalidOperationException
        + FullyQualifiedErrorId : Amazon.ConfigService.Model.NoSuchConfigurationAggregatorException,Amazon.PowerShell.Cmdlets.CFG.SelectCFGAggregateResourceConfigCmdlet
      

    I have used the same name.

  • Hi Kalaimani,

    The error message indicates that no Configuration Aggregator with the specified name exists:

    https://docs.aws.amazon.com/AWSJavaSDK/latest/javadoc/com/amazonaws/services/config/model/NoSuchConfigurationAggregatorException.html

    This can have 3 potential causes:

    • You misspelled the name of the configuration aggregator
    • Your AWS Tools for PowerShell are configured to use a region where your Configuration Aggregator is not defined
    • Your AWS Tools for PowerShell are configured to use an AWS account where your Configuration Aggregator is not defined
  • You can validate this via the following statements:
    Get-CFGConfigurationAggregatorList: Lists the defined Configuration Aggregators for your PowerShell environment
    If the list is empty you can use the following commands:
    Get-STSCallerIdentity: Lists the AWS Account ID your tools are configured to use
    Get-DefaultAWSRegion: Lists the default region your tools are configured to use

  • Thanks @Andreas_S, its working after defining the region. In order to select one Tag Value in an EC2 instance, I need one more piece of assistance. I tried the following one, but it did not work

    Select-CFGAggregateResourceConfig -ConfigurationAggregatorName xxxxxxxx -Expression "SELECT Select-CFGAggregateResourceConfig -ConfigurationAggregatorName org-cfg-aggr -Expression "SELECT accountId,awsRegion,arn,TagKey=tag['Key'], TagValue=tag['Value'],resourceId WHERE resourceType = 'AWS::EC2::Instance' AND accountID IN ('xxxxxxx')" -Region West

    Additionally, I would appreciate your assistance in obtaining the backup and backup copy status for the EC2 instance

    Select-CFGAggregateResourceConfig -ConfigurationAggregatorName XXXXXX -Expression "SELECT accountId, recoveryPointArn, details, backupJobId, backupSizeInBytes, backupVaultName, backupVaultArn, bytesTransferred, iAmRoleArn, percentDone, resourceArn, resourceType, startBy, state, statusMessage WHERE resourceType = 'AWS::Backup::Backup' AND accountID IN ('xxxxxxxxx')" -Region West

You are not logged in. Log in to post an answer.

A good answer clearly answers the question and provides constructive feedback and encourages professional growth in the question asker.

Guidelines for Answering Questions