python—发现的资源返回一个空白列表,即使资源存在

ygya80vv  于 2021-08-25  发布在  Java
关注(0)|答案(1)|浏览(393)

我一直在使用以下代码尝试aws中的所有资源:

session = boto3.Session()
client = 

    session.client('config',aws_access_key_id=access_key_id,aws_secret_access_key=secret_key,region_name=region)
resources =["AWS::EC2::CustomerGateway","AWS::EC2::EIP","AWS::EC2::Host","AWS::EC2::Instance","AWS::EC2::InternetGateway","AWS::EC2::NetworkAcl","AWS::EC2::NetworkInterface","AWS::EC2::RouteTable","AWS::EC2::SecurityGroup","AWS::EC2::Subnet","AWS::CloudTrail::Trail","AWS::EC2::Volume","AWS::EC2::VPC","AWS::EC2::VPNConnection","AWS::EC2::VPNGateway","AWS::EC2::RegisteredHAInstance","AWS::EC2::NatGateway","AWS::EC2::EgressOnlyInternetGateway","AWS::EC2::VPCEndpoint","AWS::EC2::VPCEndpointService","AWS::EC2::FlowLog","AWS::EC2::VPCPeeringConnection","AWS::IAM::Group","AWS::IAM::Policy","AWS::IAM::Role","AWS::IAM::User","AWS::ElasticLoadBalancingV2::LoadBalancer","AWS::ACM::Certificate","AWS::RDS::DBInstance","AWS::RDS::DBParameterGroup","AWS::RDS::DBOptionGroup","AWS::RDS::DBSubnetGroup","AWS::RDS::DBSecurityGroup","AWS::RDS::DBSnapshot","AWS::RDS::DBCluster","AWS::RDS::DBClusterParameterGroup","AWS::RDS::DBClusterSnapshot","AWS::RDS::EventSubscription","AWS::S3::Bucket","AWS::S3::AccountPublicAccessBlock","AWS::Redshift::Cluster","AWS::Redshift::ClusterSnapshot","AWS::Redshift::ClusterParameterGroup","AWS::Redshift::ClusterSecurityGroup","AWS::Redshift::ClusterSubnetGroup","AWS::Redshift::EventSubscription","AWS::SSM::ManagedInstanceInventory","AWS::CloudWatch::Alarm","AWS::CloudFormation::Stack","AWS::ElasticLoadBalancing::LoadBalancer","AWS::AutoScaling::AutoScalingGroup","AWS::AutoScaling::LaunchConfiguration","AWS::AutoScaling::ScalingPolicy","AWS::AutoScaling::ScheduledAction","AWS::DynamoDB::Table","AWS::CodeBuild::Project","AWS::WAF::RateBasedRule","AWS::WAF::Rule","AWS::WAF::RuleGroup","AWS::WAF::WebACL","AWS::WAFRegional::RateBasedRule","AWS::WAFRegional::Rule","AWS::WAFRegional::RuleGroup","AWS::WAFRegional::WebACL","AWS::CloudFront::Distribution","AWS::CloudFront::StreamingDistribution","AWS::Lambda::Alias","AWS::Lambda::Function","AWS::ElasticBeanstalk::Application","AWS::ElasticBeanstalk::ApplicationVersion","AWS::ElasticBeanstalk::Environment","AWS::MobileHub::Project","AWS::XRay::EncryptionConfig","AWS::SSM::AssociationCompliance","AWS::SSM::PatchCompliance","AWS::Shield::Protection","AWS::ShieldRegional::Protection","AWS::Config::ResourceCompliance","AWS::LicenseManager::LicenseConfiguration","AWS::ApiGateway::DomainName","AWS::ApiGateway::Method","AWS::ApiGateway::Stage","AWS::ApiGateway::RestApi","AWS::ApiGatewayV2::DomainName","AWS::ApiGatewayV2::Stage","AWS::ApiGatewayV2::Api","AWS::CodePipeline::Pipeline","AWS::ServiceCatalog::CloudFormationProvisionedProduct","AWS::ServiceCatalog::CloudFormationProduct","AWS::ServiceCatalog::Portfolio"]
    for resource in resources:
        response = client.list_discovered_resources(resourceType=resource)
        print(response)
        print('##################### {} #################'.format(resource))
        for i in range(len(response['resourceIdentifiers'])-1):
            print( '{} , {}'.format(response['resourceIdentifiers'][i]['resourceType'],response['resourceIdentifiers'][i]['resourceId']))

这对我以前很有用,但是现在运行它会将resourceidentifiers作为一个空白列表给出,即使资源存在。唯一的区别是,以前我使用root用户查询,现在使用iam用户查询。有什么不同吗?

piztneat

piztneat1#

最可能的答案是,您需要在boto3会话中适当设置区域,以匹配资源所在的位置。

相关问题