小编Jav*_*een的帖子

摄入时间在CloudWatch中意味着什么

在Cloudwatch事件的结构中:

'events': [
        {
            'logStreamName': 'string',
            'timestamp': 123,
            'message': 'string',
            'ingestionTime': 123,
            'eventId': 'string'
        },
    ]
Run Code Online (Sandbox Code Playgroud)

摄入时间是什么意思?

他们在这份文件中说:

ingestionTime

The time the event was ingested.
Run Code Online (Sandbox Code Playgroud)

我发现仍然不清楚.

logging amazon-web-services amazon-cloudwatch

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

使用 boto3 为将文件上传到 S3 的函数进行单元测试

我有这个功能,可以将存档文件上传到 S3 存储桶:

def upload_file_to_s3_bucket(self, bucket, file, key, log):
    if not os.path.exists(file):
        log.error("File '%s' does not exist." % file)
        tools.exit_gracefully(log)
    log.info("Uploading file '%s' to bucket '%s' ..." % (file, bucket))
    try:
        self._s3.upload_file(file, bucket, key)
    except botocore.exceptions.ClientError as e:
        log.error("Unexpected uploading error : %s" % e)
        tools.exit_gracefully(log)
    log.info("Uploading finished.")
Run Code Online (Sandbox Code Playgroud)

我想对其进行单元测试,这是到目前为止我可以写的内容:

class TestUploadFilesToS3(unittest.TestCase):
    """ Tests unitaires upload_file_to_s3_bucket"""


    def setUp(self):
        conf.LOG_FILE = "/tmp/test.log"
        conf.BUCKET_OUTPUT="name.of.the.bucket"
        conf.Conf.get_level_log()
        self.log = logger(conf.LOG_FILE, conf.LEVEL_LOG).logger
        tools.create_workdir(self.log)
        conf.WORKDIR = os.path.join(conf.LOCAL_DIR, "files/output")
        archive = "file_archive.tar.gz"
        archivePath = "/tmp/clients/file_archive.tar.gz"
        _aws = None …
Run Code Online (Sandbox Code Playgroud)

python unit-testing amazon-s3 boto3

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

计算存储桶 S3 中所有文件的大小

我想计算 python 中 S3 存储桶中所有文件的大小,这是我迄今为止尝试过的代码:

import boto3

s3_client = boto3.client('s3')
bucket = 'bucket-name'
prefix = 'path/to/folder'

len=0
response = s3_client.list_objects(Bucket = bucket,Prefix = prefix)
for file in response['Contents']:
    name = file['Key'].rsplit('/', 1)
    len+=name['ContentLength']
Run Code Online (Sandbox Code Playgroud)

我不确定如何获得文件的大小:有name['ContentLength'] 什么想法吗?

python size file amazon-s3

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

使用过滤器模式解析 cloudwatch 日志

我在通过邮件收到的 cloudwatch 中有这行 lambda 函数日志:

 /aws/lambda/sns-function | 2017/01/10/[$LATEST]425d9138c8d54ab57l0766ba74fdfd4p | 2017-01-10T00:04:30.734Z | 2017-01-10 00:04:30,734 :: ERROR :: error creating /tmp/tmpkRWp3S_20170110/file20170115.tar.gz: Command `['/bin/tar', '--create', '-z', '--file', u'/tmp/tmpkRWp3S_20170110/file20170115.tar.gz', '--', './']' returned non-zero exit status 1
Run Code Online (Sandbox Code Playgroud)

如本文档中所述,我想放置过滤器模式以仅获取重要数据。对我来说,我只想获取一次日期,因为在上面的行中,我有两次此信息:2017-01-10T00:04:30.734Z 我尝试使用这样的模式:

[...,timestamp,level,message=*ERROR*,...]
Run Code Online (Sandbox Code Playgroud)

但我收到了这个错误:

2017-01-17 10:45:58,091 :: ERROR :: logGroup: '/aws/lambda/sns-function' - logStream: 'None'
2017-01-17 10:45:58,091 :: ERROR :: An error occurred (InvalidParameterException) when calling the FilterLogEvents operation: Duplicate field '...'
Run Code Online (Sandbox Code Playgroud)

如何解析日志以获取一次日期?

amazon-web-services amazon-cloudwatch

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

模板错误:Fn::GetAtt 实例引用未定义的资源

我有这个 cloudformation 模板:

"InstanceProfileProd": {
  "Type" : "AWS::IAM::InstanceProfile",
  "Properties": {
    "Path": "/",
    "Roles" : [ { "Ref" : "InstanceRole"} ]
  }
},

"CompLayer": {
  "Type": "AWS::OpsWorks::Layer",
  "DependsOn" : "OpsWorksServiceRole",
  "Properties": {
    "AutoAssignElasticIps" : false,
    "AutoAssignPublicIps" : true,
    "CustomJson" : {
      },
      "awscli" : {
        "profils" : {
          "default" : {
            "role_arn": { "Fn::GetAtt": [ "InstanceProfileProd","Arn" ] }
          }
        }
      },
    },
    "CustomSecurityGroupIds" : { "Ref" : "SecurityGroupIds" },
    "EnableAutoHealing" : true,
    "InstallUpdatesOnBoot": false,
    "LifecycleEventConfiguration": {
      "ShutdownEventConfiguration": {
        "DelayUntilElbConnectionsDrained": false,
        "ExecutionTimeout": …
Run Code Online (Sandbox Code Playgroud)

json aws-cloudformation aws-opsworks

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

通过CloudFormation声明IAM访问密钥资源

我在模板中使用访问密钥创建了一个用户:

"MyAccessKey" : {
   "Type" : "AWS::IAM::AccessKey",
   "Properties" : {
      "UserName" : { "Ref" : "User12" }
   }
} 
Run Code Online (Sandbox Code Playgroud)

我需要在模板的输出中获取访问密钥ID和秘密密钥。怎么做 ?谢谢

access-keys aws-cloudformation

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

TypeError:在python中使用replace()时需要一个整数

我正在尝试解析日期并将其放入正确的格式,这是我迄今为止尝试过的:

import csv
import sys
import os
import re
import fnmatch
import csv
from dateutil.parser import parse as parseDate
from datetime import datetime, time, timedelta

chaine = '16/12/201602:15:00'
date = chaine[:10] + " " + chaine[11:]
print date
newd = parseDate(date, yearfirst=True)
print newd
newd = newd.replace('-','')
newd = newd.replace(':','')
print newd
Run Code Online (Sandbox Code Playgroud)

这是我得到的结果:

16/12/2016 2:15:00
2016-12-16 02:15:00
Traceback (most recent call last):
  File "t.py", line 25, in <module>
    newd = newd.replace('-','')
TypeError: an integer is required
Run Code Online (Sandbox Code Playgroud)

我在这里想念什么?

谢谢

python string

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

通过 cloudformation 创建 IAM 角色时 policyName 出错

这是角色片段:

"InstanceRole": {
  "Type": "AWS::IAM::Role",
  "Properties": {
    "AssumeRolePolicyDocument": {
      "Version" : "2012-10-17",
      "Statement": [ {
        "Effect": "Allow",
        "Principal": {
           "Service" : [ { "Fn::FindInMap": [ "Region2Principal", { "Ref": "AWS::Region" },"EC2Principal" ] } ] },
        "Action"  : [ "sts:AssumeRole" ]
      }]
    },
    "Path": "/",
    "Policies": [{
      "PolicyName": {"Fn::Join" : ["",["AWS::StackName","InstanceApi"] ] },
      "PolicyDocument": {
        "Statement": [{
          "Effect": "Allow",
          "Action": "*",
          "Resource": "*"
        }]
      }
    }]
  }
},
Run Code Online (Sandbox Code Playgroud)

这是错误: The specified value for policyName is invalid. It must contain only alphanumeric characters …

json roles aws-cloudformation amazon-iam

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

错误'EC2'对象在aws lambda函数中没有属性'instances'

测试此代码后,我收到此错误:

'EC2' object has no attribute 'instances': AttributeError
Traceback (most recent call last):
File "/var/task/lambda_function.py", line 11, in lambda_handler
instances=ec2.instances.filter(Filters=filters)
AttributeError: 'EC2' object has no attribute 'instances'
Run Code Online (Sandbox Code Playgroud)

第11行是下面代码中的最后一行

ec2 = boto3.client('ec2', region_name=region)

def lambda_handler(event, context):
    filters = [{ 'Name': 'instance-state-name', 'Values': ['running']}]
    instances=ec2.instances.filter(Filters=filters)
Run Code Online (Sandbox Code Playgroud)

这里的错误究竟在哪里?

python lambda amazon-web-services

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