我已经用Python编写了一个AWS Lambda函数,该函数可筛选实例并根据其标记方式打开或关闭它们。这将向您显示一个工作功能,以及使它工作所需的设置。如果您有任何疑问,请在评论中发布。
到目前为止,这是我的Lambda函数:
import boto3
def lambda_handler(event, context):
startStop = event['startStop']
vertical = event['vertical']
isRunning = ''
if(startStop == 'start'):
isRunning = 'stopped'
elif (startStop == 'stop'):
isRunning = 'running'
ec2 = boto3.resource('ec2')
filters = [
{
'Name': 'instance-state-name',
'Values': [isRunning]
},
{
'Name': 'tag:Vertical',
'Values': [vertical]
}
]
instances = ec2.instances.filter(Filters=filters)
runningInstances = [instance.id for instance in instances]
if len(runningInstances) > 0:
if(startStop == 'start'):
shuttingDown = ec2.instances.filter(InstanceIds=runningInstances).start()
elif (startStop == 'stop'):
shuttingDown = ec2.instances.filter(InstanceIds=runningInstances).stop()
Run Code Online (Sandbox Code Playgroud)
供参考,这是我的映射模板:
{
"startStop":"$input.params('startStop')",
"vertical":"$input.params('vertical')" …Run Code Online (Sandbox Code Playgroud) python amazon-web-services aws-sdk aws-lambda aws-api-gateway
我是 GitLab 的新手并使用 API 调用,并且对如何调用以获取存储库/项目文件和元数据感到困惑。我当前的 API 调用如下:
https://gitlab.com/api/v3/projects?private_token=privateToken
Run Code Online (Sandbox Code Playgroud)
上面一行末尾的 privateToken 被替换为我出于明显安全原因而取出的私有令牌。
这将返回给我描述我拥有的所有项目的 json,但我想更深入地查看有关存储在每个项目/存储库中的文件的特定信息。在 GitLab API 文档网站上,它列出了以下内容:
GET /projects/:id/repository/files/:file_path
Run Code Online (Sandbox Code Playgroud)
但是,由于我通常不熟悉 GitLab 和 API 调用,因此我对如何编辑我的第一个链接以检索此信息感到困惑。
理想情况下,我希望能够深入到 python 中的项目/存储库文件和元数据,而不必编辑上面的第一个链接,但我不确定这是否可行。GitLab 如何返回json?作为散列表的散列表,如果是这样,我如何浏览它?
任何关于如何解析 json 并在其中深入钻探的说明将不胜感激!
我正在使用 Python 3.6.1。
谢谢!