小编Mar*_*cin的帖子

Tkinter PIL图像不显示在功能内部

我正在使用Tkinter在Toplevel()中显示图像但是当我把它放在一个函数中时它不起作用(这是我知道的初学者)

 # -*- coding: utf-8 -*-
import Tkinter
from Tkinter import *
import tkMessageBox
from tkMessageBox import *
import Image, ImageTk
import PIL.Image, PIL.ImageTk
import os
import subprocess


root = Tk()
root.title("Test")
quin=Toplevel()    
C = Tkinter.Canvas(quin, bg="white", height = 350, width = 350)   
directory=os.path.dirname(os.path.abspath(__file__))
filename=os.path.join(directory, 'un.png')
img=PIL.Image.open(filename)
tkimg=PIL.ImageTk.PhotoImage(img)
image = C.create_image(175,175,image=tkimg)
C.grid(row=5,column=5)
def Head():
     h1 = Label(root, text = "How to Secure a Computer", fg ="white", bg = "#00b8ff", width = 6,bd=2, height =2, font = "Arial", relief = RAISED) …
Run Code Online (Sandbox Code Playgroud)

python tkinter function python-imaging-library

3
推荐指数
1
解决办法
1285
查看次数

AttributeError: 部分初始化的模块 'boto3' 没有属性 'resource'(很可能是由于循环导入)

我使用 Pycharm 并安装了 boto3 包并尝试导入 boto3 并出现属性错误。Python.exe 文件路径在项目解释器中给出

import boto3

s3 = boto3.resource('s3')
Run Code Online (Sandbox Code Playgroud)

AttributeError: 部分初始化的模块 'boto3' 没有属性 'resource'(很可能是由于循环导入)

但是相同的代码在 Python shell 中工作

boto pycharm boto3

3
推荐指数
1
解决办法
3670
查看次数

使用具有多个资源的 tag_secifications 设置启动模板

根据下面给出的文档示例,我看到实例类型的标签集。但是如果我希望将相同的标签应用于多个资源,那么我将如何设置它 https://registry.terraform.io/providers/hashicorp/aws/latest/docs/resources/launch_template

  tag_specifications {
    resource_type = "instance"

    tags = {
      Name = "test"
    }
  }
Run Code Online (Sandbox Code Playgroud)

在此输入图像描述

amazon-web-services terraform terraform-provider-aws

3
推荐指数
1
解决办法
2752
查看次数

如何使用 terraform 将来自不同区域 (us-east1) 的 ACM 证书附加到另一个区域中的应用程序负载均衡器

我使用 terraform 在 ap-southeast-1 中设置了 AWS 基础设施,但是,我想使用 aws_alb_listener 资源将在 us-east1 中创建的 ACM 证书链接到我的负载均衡器。


resource "aws_alb_listener" "https" {
  load_balancer_arn = aws_lb.main.id
  port              = 443
  protocol          = "HTTPS"
  ssl_policy        = "ELBSecurityPolicy-2016-08"
  certificate_arn   = var.acm_certificate_arn
  depends_on        = [aws_alb_target_group.main]

  default_action {
    target_group_arn = aws_alb_target_group.main.arn
    type             = "forward"
  }
}
Run Code Online (Sandbox Code Playgroud)

当我应用 terraform 时,它会引发错误。

是否可以使用 terraform 将 ACM 证书附加到来自不同区域的 alb?

我的用例是该证书还将在 AWS CloudFront 中用作 CDN。

amazon-web-services terraform terraform-provider-aws aws-acm

3
推荐指数
1
解决办法
4670
查看次数

仅返回实例 ID,在 Lambda 中使用描述实例

我正在 lambda 函数中运行以下脚本来使用标签描述 ec2 实例。但作为响应,我只需要实例 ID,而它会返回大量信息。请指导或以任何其他方式使用标签查找 ec2 insatnce id。谢谢

代码是:

import boto3
import json
from collections import defaultdict

region = 'us-east-1'

def lambda_handler(event, context):
    
    
    client = boto3.client('ec2')

    running_instances = client.describe_instances(
      Filters=[
        {
            'Name': 'tag:orgid',
            'Values': [
                'demoxx',
            ]
        },
    ],
    )

    return json.loads(json.dumps(running_instances, default=str))   
Run Code Online (Sandbox Code Playgroud)

amazon-ec2 amazon-web-services boto3 aws-lambda

3
推荐指数
1
解决办法
3094
查看次数

为什么我的事件桥规则不执行我的 Lambda 函数?

我正在尝试创建一个事件桥规则,该规则将每 30 分钟运行一次 Lambda 函数。我的代码基于我在 SO Use terraform to set up a lambda functiontriggered by a Scheduled event source上找到的答案

这是我的地形代码:

监控/main.tf:

...

module "cloudwatch_event_rule" {
  source = "./cloudwatch_event_rule"
  extra_tags = local.extra_tags
}

module "lambda_function" {
  source = "./lambda_functions"
  extra_tags = local.extra_tags
  alb_names = var.alb_names
  slack_webhook_url = var.slack_webhook_url
  environment_tag = local.environment_tag
}

module "cloudwatch_event_target" {
  source = "./cloudwatch_event_target"
  lambda_function_arn = module.lambda_function.detect_bad_rejects_on_alb_lambda_arn
  cloudwatch_event_rule_name = module.cloudwatch_event_rule.cloudwatch_event_rule_name
  extra_tags = local.extra_tags
}
Run Code Online (Sandbox Code Playgroud)

监控/lambda_functions/main.tf:

resource "aws_lambda_function" "detect_bad_rejects_on_alb" {
  filename         = var.filename
  function_name    = var.function_name
  role             = …
Run Code Online (Sandbox Code Playgroud)

amazon-web-services aws-lambda terraform aws-event-bridge

3
推荐指数
1
解决办法
2896
查看次数

允许 lambda 权限访问 Secretsmanager 值

我正在使用 Terraform 部署需要在 AWS SecretsManager 中保存机密的 lambda。

我有以下缩写的 lambda:

拉姆达


resource "aws_lambda_function" "thisThing" {
  function_name = "functionName"
  runtime = "python3.8"
  handler = "thisThing.handler"

  role = aws_iam_role.lambda_exec.arn
}

resource "aws_iam_role" "lambda_exec" {
  name = "serverless_lambda"

  assume_role_policy = jsonencode({
    Version = "2012-10-17"
    Statement = [{
      Action = "sts:AssumeRole"
      Effect = "Allow"
      Sid    = ""
      Principal = {
        Service = "lambda.amazonaws.com"
      }
      }
    ]
  })
}

resource "aws_iam_role_policy_attachment" "lambda_policy" {
  role       = aws_iam_role.lambda_exec.name
  policy_arn = "arn:aws:iam::aws:policy/service-role/AWSLambdaBasicExecutionRole"
}
Run Code Online (Sandbox Code Playgroud)

这是秘密

秘密

# Secrets

resource "aws_secretsmanager_secret" …
Run Code Online (Sandbox Code Playgroud)

amazon-web-services aws-lambda terraform terraform-provider-aws

3
推荐指数
1
解决办法
7274
查看次数

这里不希望使用“云”类型的块与 Terraform Cloud 集成

我正在按照此文档迁移本地状态以与 Terraform Cloud 集成。

https://learn.hashicorp.com/tutorials/terraform/cloud-migrate

这很简单,我只需要复制这段代码:

terraform {
  required_version = ">= 1.1.0"
  required_providers {
    random = {
      source  = "hashicorp/random"
      version = "3.0.1"
    }
  }
  cloud {
    organization = "<ORG_NAME>"
    workspaces {
      name = "Example-Workspace"
    }
  }
}
Run Code Online (Sandbox Code Playgroud)

问题是我下面的代码与上面的代码相同

terraform {
  required_version = ">= 0.14.9"
  required_providers {
    aws = {
      source = "hashicorp/aws"
      version = "~> 3.27"
    }
  }
  cloud {
    organization = "ORG"

    workspaces {
      name = "ORG_WORKSPACE"
    }
  }
}
Run Code Online (Sandbox Code Playgroud)

但它返回一个错误:

Blocks of type "cloud" are not expected …
Run Code Online (Sandbox Code Playgroud)

amazon-web-services terraform terraform-cloud

3
推荐指数
1
解决办法
2824
查看次数

ZF-如何访问子表单元素并设置其值

大家好!我在这里设置子表单元素,它工作正常.

//Setting SubForm element    
$subForm = new Zend_Form_SubForm();
$subForm->setName('sampleSubForm');
$subForm->addElement('text', 'test', array(
           'value' => 'someValue',
           'name' => 'test',
           'belongsTo' => 'sampleSubForm',
           'size' => '1',
           'maxLength' => '1',
           'decorators' => array('ViewHelper'),
        ));
$this->form->addSubForm($subForm, 'sampleSubForm');
Run Code Online (Sandbox Code Playgroud)

我仍然在摆弄并想知道如何在表单提交时访问子表单元素,以设置其值.干杯和快乐的编码!谢谢

php zend-framework zend-form-sub-form

2
推荐指数
1
解决办法
630
查看次数

在 terraform 中加载policy.json文件

我的 EKS 特定用户配置位于 json 文件中,我想将其加载到 terraform 中以应用它。

我使用 data_source aws_iam_policy_document

resource "aws_iam_policy_document" "ops_manager" {                                                                                                       
policy = file("templates/eks_user_policy.json")         
    } 
Run Code Online (Sandbox Code Playgroud)

不幸的是,当我运行terraform plan时,我得到了这个:

提供程序provider.aws不支持资源类型
“aws_iam_policy_document”。

地形版本:v0.14.9

amazon-web-services terraform terraform-provider-aws

2
推荐指数
1
解决办法
4981
查看次数