我有以下lambda函数代码,用于简单地打印S3存储桶的上传事件的Author和元数据:
from __future__ import print_function
import json
import urllib
import boto3
print('Loading function')
s3 = boto3.client('s3')
def lambda_handler(event, context):
#print("Received event: " + json.dumps(event, indent=2))
# bucket = event['Records'][0]['s3']['bucket']['name']
for record in event['Records']:
bucket = record[0]['s3']['bucket']['name']
key = record[0]['s3']['object']['key']
response = s3.head_object(Bucket=bucket, Key=key)
logger.info('Response: {}'.format(response))
print("Author : " + response['Metadata']['author'])
print("Description : " + response['Metadata']['description'])
Run Code Online (Sandbox Code Playgroud)
但是,我在测试时收到以下错误:
{
"stackTrace": [
[
"/var/task/lambda_function.py",
17,
"lambda_handler",
"for record in event['Records']:"
]
],
"errorType": "KeyError",
"errorMessage": "'Records'"
}
Run Code Online (Sandbox Code Playgroud)
访问S3对象的存储桶名称和密钥名称时,我是否做错了什么?如果没有,那么我在这里做错了什么?
我需要在我的go代码中使用config,我想从命令行加载配置路径.我尝试:
if len(os.Args) > 1 {
configpath := os.Args[1]
fmt.Println("1") // For debug
} else {
configpath := "/etc/buildozer/config"
fmt.Println("2")
}
Run Code Online (Sandbox Code Playgroud)
然后我用config:
configuration := config.ConfigParser(configpath)
Run Code Online (Sandbox Code Playgroud)
当我使用参数(或没有)启动我的go文件时,我收到类似的错误
# command-line-arguments
src/2rl/buildozer/buildozer.go:21: undefined: configpath
Run Code Online (Sandbox Code Playgroud)
我该如何正确使用os.Args?
我想从 ansible playbook 内部运行带有输入参数的 Python 脚本。我该怎么做?
我尝试过command
,但它似乎不需要任何输入参数。我也尝试过script
,但似乎只考虑 bash 脚本。
PS:我将输入参数视为--extra-vars
.
我有一个 SQS 队列,它曾经有以下策略文档。从存储桶接收 S3 事件:
{
"Version": "2008-10-17",
"Id": "example-ID",
"Statement": [
{
"Sid": "example-statement-ID",
"Effect": "Allow",
"Principal": {
"AWS": "*"
},
"Action": [
"sqs:SendMessage",
"sqs:ReceiveMessage"
],
"Resource": "arn:aws:sqs:us-east-1:<>:cypher-queue",
"Condition": {
"ArnLike": {
"aws:SourceArn": "arn:aws:s3:*:*:cypher-secondarybucket"
}
}
}
]
}
Run Code Online (Sandbox Code Playgroud)
现在,我为队列启用了服务器端加密(SSE)。而且,我已按照此文档编写加密政策声明。现在的政策声明如下所示:
{
"Version": "2008-10-17",
"Id": "example-ID",
"Statement": [
{
"Sid": "example-statement-ID",
"Effect": "Allow",
"Principal": {
"AWS": "*"
},
"Action": [
"sqs:SendMessage",
"sqs:ReceiveMessage"
],
"Resource": "arn:aws:sqs:us-east-1:<>:cypher-queue",
"Condition": {
"ArnLike": {
"aws:SourceArn": "arn:aws:s3:*:*:cypher-secondarybucket"
}
}
},
{
"Effect": …
Run Code Online (Sandbox Code Playgroud) permissions amazon-s3 amazon-sqs amazon-web-services aws-kms
亚马逊机器学习平台对情绪分析和文本分析的灵活性或支持性如何?
nlp machine-learning amazon-web-services sentiment-analysis amazon-machine-learning
类似于fig.set_size_inches(18.5, 10.5)
matplotlib的东西.
我是dynamodb的新手,试图从dynamodb获取数据.
我的python代码
import boto3
from boto3 import dynamodb
from boto3.session import Session
from boto3.dynamodb.conditions import Key, Attr
dynamodb_session = Session(aws_access_key_id='XXXXXXXXXXXXXXX',
aws_secret_access_key='XXXXXXXXXXXXXXXXXXXXXXXXXXXX',
region_name='us-east-1')
dynamodb = dynamodb_session.resource('dynamodb')
table=dynamodb.Table('Garbage_collector_table')
my_topic = "$aws/things/garbage_collector_thing/shadow/update/accepted"
response = table.get_item(TableName='Garbage_collector_table', Key={'topic':my_topic})
for res in response:
print "result ",res
Run Code Online (Sandbox Code Playgroud)
我收到以下错误
Traceback (most recent call last):
File "get-data-dynamodb-boto3.py", line 19, in <module>
response = table.get_item(TableName='Garbage_collector_table', Key={'topic': my_topic}) File
"/usr/local/lib/python2.7/dist-packages/boto3/resources/factory.py",
line 518, in do_action
response = action(self, *args, **kwargs) File "/usr/local/lib/python2.7/dist-packages/boto3/resources/action.py",
line 83, in __call__
response = getattr(parent.meta.client, operation_name)(**params) File …
Run Code Online (Sandbox Code Playgroud) 我有一个如下所示的数据集:
"user.get","search_restaurants","cuisines.get"
"user.get","search_restaurants","user.get","search_restaurants"
"order/address/get_user_addresses"
"search_restaurants","search_restaurantssearch_restaurants"
"restaurant.get","search_restaurants","order/menu","restaurant.get","restaurant.get","restaurant.get","order/menu","order/menu","restaurant.get","restaurant.getsearch_restaurantsrestaurant.get","user.get","order/menu","order/menu","get_user_reviews_filtered","order/menu","restaurant.get"
Run Code Online (Sandbox Code Playgroud)
当我运行apriori算法时:
txn1 = read.transactions(file="path", rm.duplicates=TRUE)
basket_rules <- apriori(txn1, parameter = list(sup = 0.01, conf = 0.01,target="rules"))
inspect(basket_rules)
Run Code Online (Sandbox Code Playgroud)
我得到了空白的lhs.哪个是:
{} => {cuisines.get}
等等
知道为什么会这样吗?如何解决这个问题?
我有以下代码行:
table.put_item( Item={'filename' : key, 'status' : {'M' : iocheckdict }})
Run Code Online (Sandbox Code Playgroud)
该iocheckdict
如下所示:
{'A': 'One', 'C': 'Three', 'D': 'Four', 'B': 'Two', 'E': 'Five'}
Run Code Online (Sandbox Code Playgroud)
因此,当我运行代码时,出现此错误:
An error occurred (ValidationException) when calling the PutItem operation: One or more parameter values were invalid: Type mismatch for key status expected: S actual: M
Run Code Online (Sandbox Code Playgroud)
为什么我得到这个,即使我提到M
了数据的类型?
PS:我有2列filename
,并status
在我的表
表的属性定义:
"AttributeDefinitions": [
{
"AttributeName": "filename",
"AttributeType": "S"
},
{
"AttributeName": "status",
"AttributeType": "S"
}
],
Run Code Online (Sandbox Code Playgroud)
我知道的类型status
是S,但是我在创建表时没有找到地图类型。我发现的只是string
,binary …
我有以下剧本:
- hosts: localhost
connection: local
remote_user: test
gather_facts: no
vars_files:
- files/aws_creds.yml
- files/info.yml
environment:
AWS_ACCESS_KEY_ID: "{{ aws_id }}"
AWS_SECRET_ACCESS_KEY: "{{ aws_key }}"
s3cmd_access_key: "{{ aws_id }}"
s3cmd_secret_key: "{{ aws_key }}"
tasks:
- name: Basic provisioning of EC2 instance
ec2:
assign_public_ip: no
aws_access_key: "{{ aws_id }}"
aws_secret_key: "{{ aws_key }}"
region: "{{ aws_region }}"
image: "{{image_instance }}"
instance_type: "{{ free_instance }}"
key_name: "{{ ssh_keyname }}"
count: 3
state: present
group_id: "{{ secgroup_id }}"
vpc_subnet_id: "{{ private_subnet_id }}"
wait: no …
Run Code Online (Sandbox Code Playgroud) python ×5
amazon-s3 ×2
ansible ×2
boto3 ×2
amazon-ec2 ×1
amazon-sqs ×1
arules ×1
aws-kms ×1
aws-lambda ×1
command-line ×1
go ×1
matplotlib ×1
nlp ×1
permissions ×1
r ×1
seaborn ×1