python - 使用boto3 python sdk查询aws以列出所有资源
问题描述
有没有办法通过python代码使用boto3获取aws帐户中的所有资源。我浏览了文档,没有找到任何可以解决这个问题的列表函数。
解决方案
试试这个命令。
aws config
但在运行此命令之前先启用该区域的先决条件。
导入 boto3 session = boto3.Session(profile_name='your-profilename')client = session.client('config')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::集群”,”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::项目”,”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::应用程序”,”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::域名”,”AWS::ApiGatewayV2::Stage”,”AWS::ApiGatewayV2::Api”,”AWS::CodePipeline::Pipeline”,”AWS::ServiceCatalog::CloudFormationProvisionedProduct”,”AWS::ServiceCatalog::CloudFormationProduct”,”AWS::ServiceCatalog::Portfolio”]用于资源中的资源:response = client.list_discovered_resources(resourceType=resource)print('## ##################{} #################'.format(resource))for i in range( len(response['resourceIdentifiers'])-1):print('{}, {}'.format(response['resourceIdentifiers'][i]['resourceType'],response['resourceIdentifiers'][i][ 'resourceId']))格式(响应['resourceIdentifiers'][i]['resourceType'],响应['resourceIdentifiers'][i]['resourceId']))格式(响应['resourceIdentifiers'][i]['resourceType'],响应['resourceIdentifiers'][i]['resourceId']))
推荐阅读
- scala - RDD.count上的apache spark NullPointerException
- mongodb - 如何优化 Mongo 查询以防止超时
- javascript - 未定义不是对象(评估“_this.camera”)
- spring - 模式验证:缺少序列 [user_sequence]
- python - pyspark:数据类型更改功能
- node.js - require.resolve() 参数中的斜杠是什么意思?
- java - 使用其他对象的方法对对象列表进行排序
- python - 如何在 x,y 点的二维数组中找到第一个极值?
- r - 如果给定元素不出现,则查找给定元素的索引或 NA
- pandas - 为什么会出现错误 AttributeError: 'bool' object has no attribute 'copy' 显示但一些值正在按需要打印?