答案 0 :(得分:11)
在lambda自己的cli api中管理的唯一事件源是Kinesis Streams和DynamoDb Streams。您可以使用aws lambda
在S3中管理S3存储桶事件,因为它们可以发送到SNS主题,SQS队列或Lambda功能。因此,您需要使用public class Order extends AppCompatActivity {
public ListView orderListView;
public myOrderAdapter orderAdapter;
public ArrayList<myProduct> productList, filter;
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_order);
orderListView = (ListView)findViewById(R.id.orderList);
productList = new ArrayList<myProduct>();
filter = new ArrayList<myProduct>();
for(myProduct item : productList){
//Condition before adding
if(item.productQuantity > 0) {
Log.d(TAG,item.getProductName());
filter.add(item);
}
}
orderAdapter = new myOrderAdapter(getApplicationContext(),filter);
orderListView.setAdapter(orderAdapter);
}
}
cli命令,特别是put-bucket-notification-configuration
在aws s3api
arg中,你会有类似的东西:
--notification-configuration
其中,事件是s3 events
的列表答案 1 :(得分:2)
我能够使用以下AWS CLI为lambda添加SNS触发器
aws --region eu-west-1 lambda add-permission --function-name {{LAMBDA-FUNCTION-NAME}} --statement-id {{UNIQUE-ID}} --action "lambda:InvokeFunction" --principal sns.amazonaws.com --source-arn arn:aws:sns:us-east-1:77889900:{{SNS-TOPIC-ARN}}
SNS主题也可以来自其他地区。
希望这会有所帮助。
答案 2 :(得分:1)
正如@ user1292364所述,我们需要对lambda使用add-permission。
唯一的问题是,您需要确保将 lambda到sns订阅添加了 o。否则会发生此错误
A subscription for arn:aws:lambda:eu-west-1:276xxxxxx:function:HourlyLambdaFunction on the topic HourlyLambdaFunction could not be found.
我希望以这种方式通过AWS CLI使用它:
#!/usr/bin/env bash
# Add Lambda to SNS as subscription
aws sns subscribe \
--topic-arn arn:aws:sns:eu-west-1:276xxxxxx:HourlyLambdaFunction \
--protocol lambda \
--notification-endpoint arn:aws:lambda:eu-west-1:276xxxxxx:function:HourlyLambdaFunction
# Give permissions to Lambda to access that subscription i.e. Add it through triggers
aws lambda add-permission \
--function-name HourlyLambdaFunction \
--statement-id 276xxxxxx\
--action "lambda:InvokeFunction" \
--principal sns.amazonaws.com \
--source-arn arn:aws:sns:eu-west-1:276xxxxxx:HourlyLambdaFunction
# Send message to publish and trigger lamda
aws sns publish \
--topic-arn arn:aws:sns:eu-west-1:276xxxxxx:HourlyLambdaFunction \
--subject "HourlyLambdaFunction" \
--message "{datawarehouse:banana_wh, database:banana_db, schema:banana. query:'select count(*) from banana.banana_loads;'}"
ps:代码中的\是bash脚本的换行符(如果有人想知道的话)
lambda函数的日志可以在Cloudwatch上找到