以下是我的 AWS terraform 项目的文件夹结构:
c:\terraform
??modules
? ??ec2-fullstacks
? ??main.tf
? ??variables.tf
??qa
??testappapi
??testappapi_backend.tfvars
??main.tf
??terraform.tfvars
Run Code Online (Sandbox Code Playgroud)
在模块下:
内容c:\terraform\modules\ec2-fullstacks\main.tf:
c:\terraform
??modules
? ??ec2-fullstacks
? ??main.tf
? ??variables.tf
??qa
??testappapi
??testappapi_backend.tfvars
??main.tf
??terraform.tfvars
Run Code Online (Sandbox Code Playgroud)
的c:\terraform\modules\ec2-fullstacks\variables.tf内容:
provider "aws" {
}
terraform {
backend "s3" {
encrypt = true
}
}
data "aws_ami" "ami" {
most_recent = true
filter {
name = "name"
values = ["${var.ec2_ami_name}*"]
}
}
output "ami_id" {
value = "${data.aws_ami.ami.id}"
}
Run Code Online (Sandbox Code Playgroud)
在项目(testappapi)下:
内容C:\terraform\qa\testappapi\main.tf:
variable …Run Code Online (Sandbox Code Playgroud) 我正在尝试使用Boto3创建一个仅附加托管策略的新实例角色.
我有以下内容:策略名称:my_instance_policy策略ARN:arn:aws:iam :: 123456789012:policy/my_test_policy
我想创建一个名为'my_instance_role'的角色,仅附加上述政策.
Boto3客户端具有如下所示的create_role()函数:
import boto3
client = boto3.client('iam')
response = client.create_role(
Path='string',
RoleName='string',
AssumeRolePolicyDocument='string',
Description='string'
)
Run Code Online (Sandbox Code Playgroud)
在这里,我没有看到使用策略ARN或名称的选项.我的理解是,AssumeRolePolicyDocument变量需要将json格式的策略文档转换为文本.
我可能正在寻找的方式吗?
当我运行时npx prettier --write pipeline.yml,它会格式化所有子行,包括破折号 ( -),并在父行中缩进 2 个空格,如下所示:
resources:
- name: concourse-examples
type: git
icon: github
check_every: 30m
source:
uri: https://github.com/concourse/examples
jobs:
- name: set-self
public: true
plan:
- get: concourse-examples
trigger: true
- set_pipeline: self
file: concourse-examples/pipelines/set-pipelines.yml
Run Code Online (Sandbox Code Playgroud)
我希望所有子行(除了以破折号 ( ) 开头的子行-)都从其父行缩进 2 个空格,如下所示:
resources:
- name: concourse-examples
type: git
icon: github
check_every: 30m
source:
uri: https://github.com/concourse/examples
jobs:
- name: set-self
public: true
plan:
- get: concourse-examples
trigger: true
- set_pipeline: self
file: concourse-examples/pipelines/set-pipelines.yml
Run Code Online (Sandbox Code Playgroud)
我怎样才能实现这个目标?
我可以使用以下代码轻松列出所有安全组名称:
import boto3
ec2_client = boto3.client('ec2')
print('All Security Groups:')
print('----------------')
sg_all = ec2_client.describe_security_groups()
for sg in sg_all['SecurityGroups'] :
print(sg['GroupName'])
Run Code Online (Sandbox Code Playgroud)
我试图以相同的方式列出所有子网名称,例如:
print('Subnets:')
print('-------')
sn_all = ec2_client.describe_subnets()
for sn in sn_all['Subnets'] :
print(sn['SubnetName'])
Run Code Online (Sandbox Code Playgroud)
在这里,变量sn获取所有每个子网,包括所有属性和标签,但无法找到子网的正确属性名称,例如GroupName.
我可以使用 boto3.resource('ec2') 或以下代码,但为了简单起见,我正在寻找上面使用的类似方法来列出所有安全组:
print('Subnets:')
print('-------')
sn_all = ec2_client.describe_subnets()
for sn in sn_all['Subnets'] :
for tag in sn['Tags']:
if tag['Key'] == 'Name':
print(tag['Value'])
Run Code Online (Sandbox Code Playgroud)
任何帮助是极大的赞赏。
这是我在Python 3中使用的内容:
payload={"query": """query
{
organization(login: "MY-ORG-ID") {
samlIdentityProvider {
externalIdentities(first: 10) {
edges {
node {
user {login}
samlIdentity {nameId}
scimIdentity {username}
}
}
}
}
}
}"""
}
URL = 'https://api.github.com/graphql'
HEADERS = {'accept': 'application/vnd.github.v4.idl', 'authorization': 'bearer MY-GITHUB-TOKEN'}
response = requests.post(url=URL, json=payload, headers=HEADERS)
Run Code Online (Sandbox Code Playgroud)
它运作正常.
但是,我试图在POSTMAN工具中使用此查询,但不知道如何执行此操作.我试图删除3双引号""" """,我收到Unexpected 'q'错误.当我使用双引号而不是3双引号时login: \"MY-ORG-ID\",我得到"message": "Problems parsing JSON"错误.
标头和URL没有问题.我刚刚在这里给他们完整性.
我试图找到一项服务,停止它,然后使用 Powershell 远程禁用它。它可以找到并停止,但不能禁用。为了禁用,我必须Set-Service单独运行命令。可以在一行中完成吗?
以下代码片段将停止Print Spooler服务,但不会禁用它:
$ip = "10.10.10.10"
$svc_name = "Spooler"
get-service -ComputerName $ip | Where-Object {$_.Name -eq $svc_name} | Stop-Service | Set-Service -StartupType Disabled
Run Code Online (Sandbox Code Playgroud)
以下代码片段将停止并禁用Print Spooler服务:
$ip = "10.10.10.10"
$svc_name = "Spooler"
get-service -ComputerName $ip | Where-Object {$_.Name -eq $svc_name} | Stop-Service
Set-Service $svc_name -StartupType Disabled
Run Code Online (Sandbox Code Playgroud)
Powershell 版本是5.1.14393.2969.
编辑: 以下行也将查找和禁用。所以,看起来我可以用管道给出两条指令。
get-service -ComputerName $ip | Where-Object {$_.Name -eq $svc_name} | Set-Service -StartupType Disabled
Run Code Online (Sandbox Code Playgroud) 下面是我的代码,用于读取存储在 S3 存储桶路径中的 parquet 文件。当它在路径中找到镶木地板文件时,它会起作用,但当exceptions.NoFilesFound它找不到任何文件时会给出提示。
import boto3
import awswrangler as wr
boto3.setup_default_session(profile_name="myAwsProfile", region_name="us-east-1")
path_prefix = 's3://example_bucket/data/parquet_files'
path_suffix = '/y=2021/m=4/d=13/h=17/'
table_path = path_prefix + path_suffix
df = wr.s3.read_parquet(path=table_path)
print(len(df))
Run Code Online (Sandbox Code Playgroud)
输出:
22646
Run Code Online (Sandbox Code Playgroud)
如果 S3 路径中没有文件,例如,如果我将path_suffixfrom更改'/y=2021/m=4/d=13/h=17/'为'/y=2021/m=4/d=13/h=170/',则会收到以下错误:
---------------------------------------------------------------------------
NoFilesFound Traceback (most recent call last)
<ipython-input-9-17df460412d8> in <module>
11
12 file_prefix = table_path + date_prefix
---> 13 df = wr.s3.read_parquet(path=file_prefix)
/usr/local/lib/python3.9/site-packages/awswrangler/s3/_read_parquet.py in read_parquet(path, path_suffix, path_ignore_suffix, ignore_empty, ignore_index, partition_filter, columns, validate_schema, chunked, dataset, categories, safe, map_types, use_threads, last_modified_begin, …Run Code Online (Sandbox Code Playgroud)