我有一个触发 Lambda 函数的 SQS。Lambda 函数只是接收消息并将其放入 DynamoDB。
它工作正常,但问题是我注意到消息已从 SQS 中删除,而无需在我的代码中添加 delete() 语句。
但是在代码中明确提到消息应该由消费者手动删除,否则它将再次放入SQS。
这里发生了什么 ?
我想处理流程出现问题的情况,在这种情况下,消息应该再次出现在 SQS 中,以便另一个 Lambda 可以尝试处理它。
这是我的 Lambda 代码:
import json
import time
import boto3
def lambda_handler(event, context):
message_id = event['Records'][0]['messageId']
message_receipt_handle = event['Records'][0]['receiptHandle']
message_body = event['Records'][0]['body']
print('Message received :')
print(message_body)
print('Processing message ...')
dynamo_db = boto3.client('dynamodb')
response_db = dynamo_db.put_item(
TableName='sqs-test-sbx',
Item={
'id': {
'S': message_id,
},
'Message': {
'S': message_body,
}
}
)
print('dynamodb response :')
print(response_db)
# Simulate a proceesing ...
time.sleep(10)
print('Message processed')
return …Run Code Online (Sandbox Code Playgroud) 我有一个全局变量文件,我想在不同的子文件夹中使用它。为此,我将其放在名为共享的文件夹中,然后在其他子文件夹中创建了符号链接。
shared
.global_variables.tf
s3
.gloabl_variables -> shared/global_variables.tf
.main.tf
.output.tf
.variables.tf
Run Code Online (Sandbox Code Playgroud)
我使用以下命令创建了符号链接:ln -s shared/global_variables.tf s3/global_variables.tf
现在在 S3 文件夹中,如果我运行,terraform init我会收到此错误:
Error: Failed to read file
The file "global_variables.tf" could not be read
Run Code Online (Sandbox Code Playgroud)
terraform 似乎无法识别文件的符号链接。
怎么解决呢?
谢谢
我正在尝试使用 Cloudwatch 设置警报来检测 ECS 集群中的任务何时被终止。
我按照此https://docs.aws.amazon.com/AmazonECS/latest/developerguide/cloudwatch-metrics.html#cw_running_task_count设置一个指标来跟踪服务运行的任务数量。
这是我的闹钟:
**Namespace** : AWS/ECS
**MetricName** : CPUUtilization
**ServiceName** : my_service
**ClusterName** : my_cluster
**Statistic** : Sample count
**Period** : 1minute
**Conditions** :
**Threshold type** : Static
**Whenever CPUUtilization is**... : Lower Than 1
Run Code Online (Sandbox Code Playgroud)
但它不起作用,也没有按预期生成警报。我认为这是因为如果任务被终止,它会在 1 分钟(警报中设置的时间段)内自动快速重新创建。
我尝试将时间段更改为不到一分钟,但 AWS 表示“AWS/”命名空间中的指标仅支持大于 60 秒的时间段
那么有没有办法检测任务是否被杀死呢?
谢谢
我将一个卷附加到 EC2 实例,现在当我尝试安装它时,出现此错误:
sudo mount /dev/xvdf /mnt/tmp
mount: /mnt/tmp: wrong fs type, bad option, bad superblock on /dev/xvdf, missing codepage or helper program, or other error.
Run Code Online (Sandbox Code Playgroud)
有什么问题 ?
我正在尝试使用 Terraform 构建一个 ElasticSearch 集群,但我无法分配超过 1 个子网!这真的很奇怪,因为文档中有这个:
https://www.terraform.io/docs/providers/aws/r/elasticsearch_domain.html#subnet_ids
subnet_ids -(必需)要在其中创建的 Elasticsearch 域终端节点的 VPC 子网 ID 列表。
但是当我尝试这样做时,我收到了这个错误:
错误:ValidationException:您必须准确指定一个子网
这是我的代码:
resource "aws_elasticsearch_domain" "es" {
domain_name = "${var.es_domain}-${var.environment}"
elasticsearch_version = "${var.es_version}"
cluster_config {
instance_type = "${var.es_instance_type}"
instance_count = "${var.es_instance_count}"
}
vpc_options {
subnet_ids = ["${data.aws_subnet.private_1.id}", "${data.aws_subnet.private_2.id}"]
security_group_ids = ["${aws_security_group.es.id}"]
}
snapshot_options { automated_snapshot_start_hour = "${var.es_automated_spanshot_start_hour}" }
ebs_options {
ebs_enabled = true
volume_type = "standard"
volume_size = "20"
}
access_policies = <<CONFIG
{
"Version": "2012-10-17",
"Statement": [
{
"Action": "es:*",
"Principal": "*",
"Effect": …Run Code Online (Sandbox Code Playgroud) 我有以下项目结构来使用 Terraform 在 AWS 上构建 Lambda 函数:
\n\n.\n\xe2\x94\x9c\xe2\x94\x80\xe2\x94\x80 aws.tf\n\xe2\x94\x9c\xe2\x94\x80\xe2\x94\x80 dev.tfvars\n\xe2\x94\x9c\xe2\x94\x80\xe2\x94\x80 global_variables.tf -> ../shared/global_variables.tf\n\xe2\x94\x9c\xe2\x94\x80\xe2\x94\x80 main.tf\n\xe2\x94\x9c\xe2\x94\x80\xe2\x94\x80 module\n\xe2\x94\x82 \xe2\x94\x9c\xe2\x94\x80\xe2\x94\x80 data_source.tf\n\xe2\x94\x82 \xe2\x94\x9c\xe2\x94\x80\xe2\x94\x80 main.tf\n\xe2\x94\x82 \xe2\x94\x9c\xe2\x94\x80\xe2\x94\x80 output.tf\n\xe2\x94\x82 \xe2\x94\x9c\xe2\x94\x80\xe2\x94\x80 role.tf\n\xe2\x94\x82 \xe2\x94\x9c\xe2\x94\x80\xe2\x94\x80 security_groups.tf\n\xe2\x94\x82 \xe2\x94\x9c\xe2\x94\x80\xe2\x94\x80 sources\n\xe2\x94\x82 \xe2\x94\x82 \xe2\x94\x9c\xe2\x94\x80\xe2\x94\x80 function1.zip\n\xe2\x94\x82 \xe2\x94\x82 \xe2\x94\x94\xe2\x94\x80\xe2\x94\x80 function2.zip\n\xe2\x94\x82 \xe2\x94\x94\xe2\x94\x80\xe2\x94\x80 variables.tf\n\xe2\x94\x94\xe2\x94\x80\xe2\x94\x80 vars.tf\nRun Code Online (Sandbox Code Playgroud)\n\n在 .main.tf 文件中,我有以下代码将创建 2 个不同的 lambda 函数:
\n\nmodule "function1" {\n source = "./module"\n\n function_name = "function1"\n source_code = "function1.zip"\n\n runtime = "${var.runtime}"\n memory_size = "${var.memory_size}"\n timeout = "${var.timeout}"\n aws_region = "${var.aws_region}"\n vpc_id = "${var.vpc_id}"\n}\n\n\nmodule "function2" {\n source = "./module"\n\n function_name = …Run Code Online (Sandbox Code Playgroud) 我想在 DynamoDB 中存储 Elasticsearch 域的标签列表,但遇到一些错误。
我使用 list_tags() 函数获取标签列表: https://boto3.amazonaws.com/v1/documentation/api/latest/reference/services/es.html#ElasticsearchService.Client.list_tags
response = client.list_tags(
ARN='string'
)
Run Code Online (Sandbox Code Playgroud)
它返回:
{
'TagList': [
{
'Key': 'string',
'Value': 'string'
},
]
}
Run Code Online (Sandbox Code Playgroud)
这是他们在文档中所说的:响应结构
(dict) -- ListTags 操作的结果。包含所有请求的 Elasticsearch 域的标签。TagList (list) -- 请求的 Elasticsearch 域的标签列表。(dict) -- 指定资源标签的键值对。
现在我尝试使用各种方式在 DynamoDB 中插入列表,但我总是收到错误:
':TagList': {
'M': response_list_tags['TagList']
},
Run Code Online (Sandbox Code Playgroud)
参数 ExpressionAttributeValues.:TagList.M 的类型无效,值:[{'Key': 'Automation', 'Value': 'None'}, {'Key': 'Owner', 'Value': 'owner'}, {'Key': 'BU', 'Value': 'DS'}, {'Key': '支持', 'Value': 'teamA'}, {'Key': '注意', 'Value': ' '}, {'Key': '环境', 'Value': 'dev'}, {'Key': 'Creator', 'Value': ''}, {'Key': …
为了测试我的 AutoScaling 组,我想模拟一个巨大的 CPU 使用率,以便创建一个新实例(基于我在 Cloudwatch 中配置的指标:平均 CPU >= 60)
EC2 实例是一个简单的 t2.micro,我使用了压力命令:stress -c 1 -t 400s
我可以在顶部看到进程已经启动并且 CPU 使用率为 100%,但问题是它不是恒定的。有时它掺杂到 10% 有时它高达 100%,并且在 cloudwatch 监控中,即使在 5 分钟的压力之后,CPU 平均使用率也低于 20%!
我尝试了其他参数(压力 -c 2 或压力 -c 4),这是同一回事。我也试过这个命令:是> /dev/null &
Cloudwatch 始终无法看到 100% 的 CPU 使用率。
有什么问题 ?亚马逊是否有任何保护措施来限制 CPU 的巨大负载?
谢谢你的帮助。
我在 Terraform 中有这个政策:
{
"Version": "2012-10-17",
"Statement": [
{
"Effect": "Allow",
"Principal": "*",
"Action": "execute-api:Invoke",
"Resource": "*",
"Condition": {
"IpAddress": {
"aws:SourceIp": "${source_ip}"
}
}
}
]
}
Run Code Online (Sandbox Code Playgroud)
我有一个变量authorized_ip定义如下:
variable "authorized_ip" {
default = [
"x.x.x.x/x",
"x.x.x.x/x",
]
}
Run Code Online (Sandbox Code Playgroud)
现在我这样调用 Json 策略:
data "template_file" "apigw_policy" {
template = "${file("${path.module}/template/apigateway_policy.json.template")}"
vars = {
source_ip = "${var.authorized_ip}"
}
}
Run Code Online (Sandbox Code Playgroud)
但我收到此错误:
属性“vars”的值不合适:元素“source_ip”:需要字符串。
所以 Terraform 需要一个字符串而不是列表。如何将列表转换为字符串以获得这样的结果:
"IpAddress": {
"aws:SourceIp": [
"x.x.x.x/x",
"x.x.x.x/x"
]
}
Run Code Online (Sandbox Code Playgroud) 我将在 AWS 上启动一个新的 Terraform 项目。VPC 已经创建,我想知道将它集成到我的代码中的最佳方式是什么。我是否必须再次创建它并且 Terraform 会检测到它并且不会覆盖它?或者我必须为此使用数据源吗?或者还有其他最好的方法,比如 Terraform Import ?
我还希望将来能够在其他区域或其他账户中部署整个基础设施。
谢谢。