- mongodb - 在 MongoDB mapreduce 中,如何展平值对象?
- javascript - 对象传播与 Object.assign
- html - 输入类型 ="submit"Vs 按钮标签它们可以互换吗?
- sql - 使用 MongoDB 而不是 MS SQL Server 的优缺点
我正在运行一个一次性的 Fargate 任务,该任务运行一个小型 python 脚本。任务定义配置为使用 awslogs
将日志发送到 Cloudwatch,但我遇到了一个非常奇怪的间歇性问题。
日志有时会出现在新创建的 Cloudwatch 流中,有时不会。我已经尝试删除部分代码,现在,这就是我所拥有的。
当我删除 asyncio/aiohttp 获取逻辑时,打印语句会正常显示在 Cloudwatch 日志中。虽然由于问题是间歇性的,但我不能 100% 确定这会一直发生。
但是,由于包含了获取逻辑,我有时会在 Fargate 任务退出后得到完全为空的日志流。没有日志显示“工作开始”、“工作结束”或“将文件放入 S3”。也没有错误日志。尽管如此,当我检查 S3 存储桶时,创建了具有相应时间戳的文件,表明脚本确实运行完成。我无法理解这怎么可能。
#!/usr/bin/env python3.6
import asyncio
import datetime
import time
from aiohttp import ClientSession
import boto3
def s3_put(bucket, key, body):
try:
print(f"Putting file into {bucket}/{key}")
client = boto3.client("s3")
client.put_object(Bucket=bucket,Key=key,Body=body)
except Exception:
print(f"Error putting object into S3 Bucket: {bucket}/{key}")
raise
async def fetch(session, number):
url = f'https://jsonplaceholder.typicode.com/todos/{number}'
try:
async with session.get(url) as response:
return await response.json()
except Exception as e:
print(f"Failed to fetch {url}")
print(e)
return None
async def fetch_all():
tasks = []
async with ClientSession() as session:
for x in range(1, 6):
for number in range(1, 200):
task = asyncio.ensure_future(fetch(session=session,number=number))
tasks.append(task)
responses = await asyncio.gather(*tasks)
return responses
def main():
try:
loop = asyncio.get_event_loop()
future = asyncio.ensure_future(fetch_all())
responses = list(filter(None, loop.run_until_complete(future)))
except Exception:
print("uh oh")
raise
# do stuff with responses
body = "whatever"
key = f"{datetime.datetime.fromtimestamp(time.time()).strftime('%Y-%m-%d_%H-%M-%S')}_test"
s3_put(bucket="my-s3-bucket", key=key, body=body)
if __name__ == "__main__":
print("Job starting")
main()
print("Job complete")
FROM python:3.6-alpine
COPY docker/test_fargate_logging/requirements.txt /
COPY docker/test_fargate_logging/dostuff.py /
WORKDIR /
RUN pip install --upgrade pip && \
pip install -r requirements.txt
ENTRYPOINT python dostuff.py
{
"ipcMode": null,
"executionRoleArn": "arn:aws:iam::xxxxxxxxxxxx:role/ecsInstanceRole",
"containerDefinitions": [
{
"dnsSearchDomains": null,
"logConfiguration": {
"logDriver": "awslogs",
"options": {
"awslogs-group": "test-fargate-logging-stg-log-group",
"awslogs-region": "ap-northeast-1",
"awslogs-stream-prefix": "ecs"
}
},
"entryPoint": null,
"portMappings": [],
"command": null,
"linuxParameters": null,
"cpu": 256,
"environment": [],
"ulimits": null,
"dnsServers": null,
"mountPoints": [],
"workingDirectory": null,
"secrets": null,
"dockerSecurityOptions": null,
"memory": 512,
"memoryReservation": null,
"volumesFrom": [],
"image": "xxxxxxxxxxxx.dkr.ecr.ap-northeast-1.amazonaws.com/test-fargate-logging-stg-ecr-repository:xxxxxxxxxxxxxxxxxxxxxxxxxxxx",
"disableNetworking": null,
"interactive": null,
"healthCheck": null,
"essential": true,
"links": null,
"hostname": null,
"extraHosts": null,
"pseudoTerminal": null,
"user": null,
"readonlyRootFilesystem": null,
"dockerLabels": null,
"systemControls": null,
"privileged": null,
"name": "test_fargate_logging"
}
],
"placementConstraints": [],
"memory": "512",
"taskRoleArn": "arn:aws:iam::xxxxxxxxxxxx:role/ecsInstanceRole",
"compatibilities": [
"EC2",
"FARGATE"
],
"taskDefinitionArn": "arn:aws:ecs:ap-northeast-1:xxxxxxxxxxxx:task-definition/test-fargate-logging-stg-task-definition:2",
"family": "test-fargate-logging-stg-task-definition",
"requiresAttributes": [
{
"targetId": null,
"targetType": null,
"value": null,
"name": "ecs.capability.execution-role-ecr-pull"
},
{
"targetId": null,
"targetType": null,
"value": null,
"name": "com.amazonaws.ecs.capability.docker-remote-api.1.18"
},
{
"targetId": null,
"targetType": null,
"value": null,
"name": "ecs.capability.task-eni"
},
{
"targetId": null,
"targetType": null,
"value": null,
"name": "com.amazonaws.ecs.capability.ecr-auth"
},
{
"targetId": null,
"targetType": null,
"value": null,
"name": "com.amazonaws.ecs.capability.task-iam-role"
},
{
"targetId": null,
"targetType": null,
"value": null,
"name": "ecs.capability.execution-role-awslogs"
},
{
"targetId": null,
"targetType": null,
"value": null,
"name": "com.amazonaws.ecs.capability.logging-driver.awslogs"
},
{
"targetId": null,
"targetType": null,
"value": null,
"name": "com.amazonaws.ecs.capability.docker-remote-api.1.19"
}
],
"pidMode": null,
"requiresCompatibilities": [
"FARGATE"
],
"networkMode": "awsvpc",
"cpu": "256",
"revision": 2,
"status": "ACTIVE",
"volumes": []
}
logging
库也发生了问题,我将其更改为 print
以排除 logging
最佳答案
我也遇到过同样的问题;在 CloudWatch 中间歇性丢失 ECS Fargate 任务的日志。
虽然我无法回答为什么会发生这种情况,但我可以提供一个我刚刚测试过的解决方法。
升级到 Python 3.7 版本(我看到您使用的是 3.6。我遇到同样的问题时也是如此)。
我现在可以查看我的所有日志,并且受益于最新版本的 Python。
我希望这对你有所帮助。
关于python - AWS Fargate 任务 - awslogs 驱动程序 - 间歇性日志,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/54084601/
AWS ECS Fargate 启动和运行 docker 镜像的最短/平均时间是多少? 为了争论,45MB anapsix/alpine-java图片。 我想研究使用 ECS Fargate 来加快在
我已在 AWS Fargate 上部署了我的 asp.net core 应用程序,一切正常。我正在使用 awslogs 驱动程序,日志已正确发送到 cloudwatch。但是经过几天的正确工作,我现在
我已在 AWS Fargate 上部署了我的 asp.net core 应用程序,一切正常。我正在使用 awslogs 驱动程序,日志已正确发送到 cloudwatch。但是经过几天的正确工作,我现在
我在 fargate 上运行一个任务,CPU 为 2048,内存为 8192。运行一段时间后的任务因错误而停止 container was stopped as it ran out of memor
我有一个在 ECS/Fargate 上运行的 Node.js 应用程序。我想设置一些环境变量,根据我的阅读,这应该在任务定义中完成。但是,在最初定义任务后似乎没有任何方法可以编辑环境变量。当我查看任务
我有一个给定的 AWS fargate 任务定义。 do_something 调用不支持超过 4 个并发消费者的下游服务。因此,我必须找到一种方法来限制同时运行的并发 do_something far
我有一个用于存储容器日志的 AWS EFS 共享。 我想将此 nfs 共享 (aws efs) 挂载到 AWS Fargate。可能吗? 任何支持文档链接将不胜感激。 最佳答案 你可以这样做since
我收到“不支持所请求的一项或多项功能。”尝试在AWS FARGATE上从Amazon EFS装载卷时发生错误。 最佳答案 编辑您的服务并将“平台版本”更新为1.4.0 您可以在terraform中通过
我正在尝试将 Fargate 服务添加为 Application Load Balancer 目标,但它总是获取错误的容器端口。任务定义有两个容器:端口 8080 上的应用程序和端口 443 上的 n
我正在尝试最简单的部署来在 Fargate 中启动并运行 HTTPS Web 服务器。 我已使用 Amazon Certificate Manager 创建 public certificate .
我在 aws eks 中有一个带有 Fargate 配置文件的 kubernetes 集群。当我尝试在 kube-system 命名空间中运行 aws 负载均衡器 Controller 或指标服务器时
AutoScalingGroup 需要 LaunchConfiguration 问题是 LaunchConfiguration 需要 ImageId 和其他参数等参数,因为我使用容器,所以我没有这些参
我们有一个基于 CPU 和内存为 ecs 容器化应用程序配置目标跟踪自动缩放的简单示例。我们通过以下代码自动配置了 4 个警报(2 个 CPU - 1 个放大,1 个缩小,2 个内存,1 个放大和 1
我们有一个旧的 Java 应用程序在 Jboss As 7.1.1 中运行。目前,此应用程序在 AWS EC2 实例类型 t3.medium 上运行,该实例类型为 2 个 CPU 内核和 4GB 内存
如何配置 ECS Fargate + Cloudwatch 以包含特定文件位置。 我有 app-access.log 我的框架将所有访问日志存放在其中。Cloudwatch 目前仅使用来 self 的
我正在使用以下命令启动单个 ECS Fargate 任务: aws ecs run-task --cluster Fargate \ --task-definition $ECR_REPO-run-
我的Nginx Dockerfile: FROM nginx:1.15.12-alpine RUN rm /etc/nginx/conf.d/default.conf COPY ./nginx/ngi
我们正在尝试在 AWS ECS 上启动一个 fargate 容器。在容器定义中,我们有 "command": [ "/bin/bash", "-c",
目前我正在研究如何在 AWS 上编排我们的容器化微服务。ECS 的 Fargate 选项看起来很有前途,无需管理 EC2 实例。 尽管在 Fargate 中启动“任务”所需的时间非常长,即使对于简单的
我有一个 AWS FARGATE 任务,它正在运行一个相对简单的 python 应用程序(具有从 python:3.6-stretch 构建的 Docker 镜像)。它使用 Amazon EC2 任务
我是一名优秀的程序员,十分优秀!