python - Discovered resources returning a blank list even when resources exist AWS
问题描述
I've been trying all the resources in AWS , using the following code :
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']))
This has worked for me before, however running it now gives out the resourceidentifiers as a blank list,even though the resources exist. The only difference is that previously I queried using Root user and now from IAM user. Does it cause any difference?
解决方案
最可能的答案是您需要在 boto3 会话中适当地设置区域以匹配您的资源所在的位置。
推荐阅读
- batch-file - 批处理完成后保持 Octave 打开
- java - 是否可以在 java if 语句中使用字符串
- urlencode - GNU mailutils:如何在邮箱模式中编码'@'和'$'
- ubuntu - 无法为所有用户将根 CA 导入 Ubuntu
- javascript - AWS 控制台的 SessionBox 样式扩展:您可以使用 Chrome 扩展 API 创建新的 chrome 配置文件吗?
- sql - 从另一个表插入条件数据
- python - 如何在 pydantic 中重用 root_validator
- java - 获取 - 包 org.json 不存在 - 无法使用 JSONArray / JSONObject
- django - 为什么我会收到 heroku 错误:App 与 buildpack 不兼容
- flutter - 在颤动中对齐特定字符