小编Tee*_*Kay的帖子

配置 CloudWatch Events 以使用 Terraform 将输入发送到 Lambda 函数

我想配置 CloudWatch Events 以使用 Terraform 将输入发送到 Lambda 函数。我使用以下脚本来执行此操作:

resource "aws_cloudwatch_event_rule" "aa-rule-event" {
  count               = "${var.count}"
  name                = "${var.application_name}-${element(var.names, count.index)}"
  description         = "${element(var.descriptions, count.index)}"
  schedule_expression = "${element(var.cron-expressions, count.index)}"
  is_enabled          = "${element(var.rule-status-states, count.index)}"
}

resource "aws_cloudwatch_event_target" "aa-rule-target" {
  count     = "${var.count}"
  rule      = "${var.application_name}-${element(var.names, count.index)}"
  target_id = "CloudWatchToLambda"
  arn       = "arn:aws:lambda:${var.aws_region}:${var.aws_account_number}:function:${var.application_name}-${element(var.target-lambda-function, count.index)}"
}
Run Code Online (Sandbox Code Playgroud)

我需要通过此 CloudWatch Event 向目标 Lambda 提供输入。我知道可以配置输入,但是如何在 Terraform 中配置它?

amazon-web-services amazon-cloudwatch terraform terraform-provider-aws

8
推荐指数
1
解决办法
7776
查看次数

为Custom ListView的每个项添加一个下拉菜单

我有一个完美的自定义列表视图.现在,我希望列表中的每个项目都有一个下拉菜单,这样当用户点击列表中的任何项目时,下拉菜单会显示两个选项 - 编辑和删除.根据用户的选择,列表视图项被处理.

我想知道将下拉菜单添加到每个listview项的方法.

列表项的xml文件 -

<?xml version="1.0" encoding="utf-8"?> 
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent" android:layout_height="120dp"
android:background="#FFFFFF">
<CheckBox
    android:layout_width="wrap_content"
    android:layout_height="wrap_content"
    android:layout_centerVertical="true"
    android:id="@+id/chkitem"
    android:layout_alignParentLeft="true"
   />
<TextView android:id="@+id/textTitle"
    android:layout_width="200dp"
    android:layout_height="60dp"
    android:textSize="15dp"
    android:textColor="#000000"
    android:textStyle="bold"
    android:gravity="fill"
    android:layout_toRightOf="@+id/chkitem"
    />
<TextView
    android:layout_width="200dp"
    android:layout_height="60dp"
    android:id="@+id/detail"
    android:textSize="15dp"
    android:textStyle="italic"
    android:gravity="fill"
    android:layout_toRightOf="@+id/chkitem"
    android:layout_below="@+id/textTitle"/>
    </RelativeLayout>
Run Code Online (Sandbox Code Playgroud)

适配器类

 public class list_addr_adapter extends ArrayAdapter<list_addr> {

Context context;
int layoutResourceId;



public list_addr_adapter(Context context, int layoutResourceId,          List<list_addr> items) {
    super(context, layoutResourceId, items);
    this.layoutResourceId = layoutResourceId;
    this.context = context;
    //  this.listener=callback;
}

/*private view holder class*/
private class ViewHolder { …
Run Code Online (Sandbox Code Playgroud)

android listview android-custom-view android-arrayadapter drop-down-menu

6
推荐指数
1
解决办法
9756
查看次数

读取 DynamoDB 表的所有项目

我想读取 DynamoDb 表的所有项目。我正在使用 table.scan() 函数。它正在给我回应。但是,输出以随意的方式排列。我应该得到这样的输出 -

{
"Items": [
{
  "Name": "ABC",
  "Location": "sdkjc",
  "id": "abc"
},

{
  "Name": "DEF",
  "Location": "jfyef",
  "id": "def"
}
]
}
Run Code Online (Sandbox Code Playgroud)

但我得到 -

{
"Items": [
{
  "Name": "ABC",
  },
  {
  "Location": "sdkjc",
  "id": "abc"
  },

  {
  "Name": "DEF",
  "Location": "jfyef",
  },
  {
  "id": "def"
}
]
}
Run Code Online (Sandbox Code Playgroud)

代码 -

 import boto3
 dynamodb = boto3.resource("dynamodb")
 table = dynamodb.Table(event['tableName'])
 response = table.scan()
 print (response)
Run Code Online (Sandbox Code Playgroud)

输出中没有模式。可能是什么问题?

python json amazon-dynamodb boto3 aws-lambda

5
推荐指数
1
解决办法
1305
查看次数

仅从 s3 存储桶文件夹中获取文件名

我有一个名为“Sample_Bucket”的 s3 存储桶,其中有一个名为“Sample_Folder”的文件夹。我只需要获取文件夹“Sample_Folder”中所有文件的名称。

我正在使用以下代码来这样做 -

import boto3
s3 = boto3.resource('s3', region_name='us-east-1', verify=False)
    bucket = s3.Bucket('Sample_Bucket')
    for files in bucket.objects.filter(Prefix='Sample_Folder):
        print(files)
Run Code Online (Sandbox Code Playgroud)

变量文件包含以文件名作为关键字的对象变量。

s3.ObjectSummary(bucket_name='Sample-Bucket', key='Sample_Folder/Sample_File.txt')
Run Code Online (Sandbox Code Playgroud)

但我只需要文件名。我如何提取它?或者有其他方法可以做到吗?

python amazon-s3 amazon-web-services python-3.x aws-lambda

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

选择状态不指向下一个状态 - AWS

我有以下步骤功能。执行在选择状态下失败。

"States": {
    "Process": {
        "Type": "Task",
        "Resource": "arn:aws:lambda:us-east-1:123:function:dummy1",
        "OutputPath": "$",
        "Next": "ChoiceStatePre"
    },

    "ChoiceStatePre": {
        "Type": "Choice",
        "Choices": [{
            "Variable": "$.status_pre",
            "Next": "Series0",
            "NumericEquals": 1
        }, {
            "Variable": "$.status_pre",
            "Next": "MatchStatePre",
            "NumericEquals": 8
        }]
    },
    "MatchStatePre": {
        "Type": "Task",
        "Next": "PreProcess",
        "Resource": "arn:aws:states:us-east-1:123:activity:dummy2"
    },
    "Series0": {
        "Resource": "arn:aws:lambda:us-east-1:123:function:dummy3",
        "Type": "Task",
        "InputPath": "$.seq0.step0",
        "ResultPath": "$.seq0.step0",
        "OutputPath": "$",
        "Next": "ChoiceStateTrigger0"
    }
}
Run Code Online (Sandbox Code Playgroud)

错误 -

{
"error": "States.Runtime",
"cause": "An error occurred while executing the state 'ChoiceStatePre' 
(entered at the event id …
Run Code Online (Sandbox Code Playgroud)

json amazon-web-services aws-step-functions

4
推荐指数
1
解决办法
2165
查看次数

适配器上的getItemCount()返回0

我创建了一个工作正常的适配器。现在,我需要计算适配器中数据项的数量。我正在使用函数getItemcount(),但每次都得到0。另外,我正在使用Firebase处理我的数据库。

  final Firebase mRoot = new Firebase(FIREBASE_URL);
  mPosts= mRoot.child("posts");
  rvPosts.setHasFixedSize(true); //for performance improvement
    rvPosts.setLayoutManager(new LinearLayoutManager(this));    //for vertical list

   postAdapter = new FirebaseRecyclerAdapter<Hello, PostViewHolder>(Hello.class, R.layout.view_hello, PostViewHolder.class, mPosts.orderByChild("postedBy")) {

            @Override
            protected void populateViewHolder(final PostViewHolder postViewHolder, final Hello hello, int i) {
              //do something
         }
        };
        rvPosts.setAdapter(postAdapter);
        int postForSelect = postAdapter.getItemCount();
Run Code Online (Sandbox Code Playgroud)

可能是什么问题?

android android-adapter firebase firebase-realtime-database firebaseui

3
推荐指数
2
解决办法
3047
查看次数

更新 dynamoDB 中的项目

我正在尝试更新 DynamoDB 表中的项目。我编写的代码正在更新该项目,但是当我添加标题为“源/目标”的列时,它给出了“ValidationException”异常。

用于更新的代码 -

dynamodb = boto3.resource('dynamodb')
table = dynamodb.Table("test")
response = table.update_item(
        Key={
        'id': "test_id            
        },
        UpdateExpression="set source/target= :st, user_name= :usr",
        ExpressionAttributeValues={
            ':st' : event['source/target'],
            ':usr' : event['user_name']
                },
        ReturnValues="UPDATED_NEW"
    )
Run Code Online (Sandbox Code Playgroud)

我得到的错误是 -

调用UpdateItem操作时发生错误(ValidationException):Invalid UpdateExpression:语法错误;标记:\"/\",附近:\"源/目标\""

怎么解决这个问题呢?

python amazon-dynamodb aws-lambda validationexception

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

从 Cloud Storage 读取具有确定前缀但随机后缀的文件

我使用以下代码从 Cloud Functions 读取 Google Cloud Storage 中的文件内容。这里定义了文件名(filename)。我现在的文件有明确的前缀,但后缀可以是任何东西。示例 - ABC-khasvbdjfy7i76.csv

如何读取此类文件的内容?

我知道会有“ABC”作为前缀。但后缀可以是任意的。

storage_client = storage.Client()
bucket = storage_client.get_bucket('test-bucket')
blob = bucket.blob(filename)
contents = blob.download_as_string()
print("Contents : ")
print(contents)
Run Code Online (Sandbox Code Playgroud)

file python-3.x google-cloud-storage google-cloud-platform google-cloud-functions

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

Django 中的循环导入

我一直在尝试使用 Django 运行客户端-服务器应用程序。当我尝试在 Django 中运行我的服务器时,它给了我以下错误。

django.core.exceptions.ImproperlyConfigured:包含的 URLconf '' 似乎没有任何模式。如果您在文件中看到有效模式,则问题可能是由循环导入引起的。

项目 urls.py -

from django.conf.urls import url,include
from django.contrib import admin
urlpatterns = [
url(r'^admin/', admin.site.urls),
url(r'^', include('chat.views')),
] 
Run Code Online (Sandbox Code Playgroud)

应用程序的 views.py -

from django.shortcuts import render
from django.http import JsonResponse
def home(request):
if request.method == 'POST':

    if request.is_ajax():

       //code
        return JsonResponse(data)

return render(request,'index.html')
Run Code Online (Sandbox Code Playgroud)

我哪里错了?

python django django-views request-response

-1
推荐指数
1
解决办法
4254
查看次数