我当前的堆栈是这样的:
我的数据库使用subcognito 生成的 id 作为 userId,因此它们是相同的。我还将电子邮件地址复制为数据库中的用户名。我的目的是使用 Cognito 进行身份验证,并使用我自己的数据库来实现我的应用程序的功能。
但是,如果用户希望更新他们的电子邮件地址,我需要在 cognito 和我的数据库中对此进行修改。我第一次尝试在我的 lambda 中使用 cognito 进行调用admin_update_user_attributes,但很快意识到它被阻止对互联网进行外部调用,所以我创建了一个 nat 网关,它可以工作,但成本太高了!
我的第二个想法是通过 cognito,让我的前端进行调用,然后让 cognito 触发 lambda 来更新我的数据库,但我认为这是不可能的。
是否有配置或我缺少的东西能够通过 API 网关通过 lambda 访问 AWS cognito,因为它们都是 AWS 服务。
我不想通过前端进行两个单独的调用,因为这会产生一个完成但另一个不完成的风险。
谢谢
amazon-cognito aws-lambda aws-api-gateway api-gateway amazon-cognito-triggers
该代码用于执行以下操作
RequestId:9f4fb9ed-88db-442a-bc4f-079744f5bbcf 错误:运行时退出但未提供原因 Runtime.ExitError
import ipaddress
import os
import time
from datetime import datetime
from typing import Dict, List, Optional
import boto3
from botocore.exceptions import ClientError, ParamValidationError
from pynamodb.attributes import UnicodeAttribute, UTCDateTimeAttribute
from pynamodb.exceptions import DoesNotExist
from pynamodb.models import Model
def lambda_handler(event, context):
"""Registers or de-registers private DNS resource records for a given EC2 instance."""
# Retrieve details from invocation event object.
try:
account_id = event["account"]
instance_id = event["detail"]["instance-id"] …Run Code Online (Sandbox Code Playgroud) 我的项目结构如下:
MyProject
layers
myLayer1
nodejs
node_modules
myLayer1
myExtension.js
lambda1
handler.js
lambda2
handler.js
jsconfig.json
Run Code Online (Sandbox Code Playgroud)
myExtension.js
module.exports.myTest = () => {
return 'My extension test';
};
Run Code Online (Sandbox Code Playgroud)
处理程序.js
const myext = require('myLayer1');
module.exports.handler = async (event) => {
return {
statusCode: 200,
body: JSON.stringify({
message: myext.myTest()
})
}};
Run Code Online (Sandbox Code Playgroud)
当我部署到 AWS 时,一切正常。但我无法在本地计算机上运行/调试它。
根据我的发现,在这种情况下 jsconfig.json 文件应该有助于映射路径,但是 VSCode/NodeJS 会忽略我在那里编写的任何内容(我尝试将其放置在 MyProject 根文件夹和 lambda 文件夹中)。
如果我将 handler.js 中的“require”更改为:
const myext = require('./layers/myLayer1/nodejs/node_modules/myLayer1');
Run Code Online (Sandbox Code Playgroud)
当我将代码部署到 AWS 时,这显然会破坏代码。
RDS proxy 的文档中指出,当应用程序使用准备好的语句时,连接会自动固定:
准备好的语句会导致代理固定会话。无论准备好的语句使用 SQL 文本还是二进制协议,此规则都适用。( https://docs.aws.amazon.com/AmazonRDS/latest/AuroraUserGuide/rds-proxy.html )
使用 RDS 代理时,我应该如何保护我的应用程序免受 SQL 注入?我使用此服务是为了在我的微服务中更快地与数据库连接,因此我希望重用该连接。
寻找一种将发送到 lambda 的消息延迟 5 秒的方法。
因此,lambda 收到消息 1,然后 5 秒后收到消息 2,然后 5 秒后收到消息 3,等等,比如说一千条消息。
正在查看 SQS 延迟队列和消息计时器,但它们并不正是我正在寻找的。
Step Functions 使用等待,但对于我需要的规模来说,这会很昂贵。
理想情况下,需要一个 SQS 队列来限制消息仅每 5 秒发送一次,有什么办法可以做到这一点吗?
ps 不担心它是 SQS,只需要一个解决方案
我尝试使用confluence-kafka python 库通过 lambda 函数管理我的集群,但该函数失败并出现错误:
"Unable to import module 'Test': No module named 'confluent_kafka.cimpl'"
Run Code Online (Sandbox Code Playgroud)
我的要求.txt
requests
confluent-kafka
Run Code Online (Sandbox Code Playgroud)
为了创建 zip 文件,我将代码移动到虚拟环境的 site-packages 位置并压缩所有内容。
Python代码:
import confluent_kafka.admin
import requests
def lambda_handler(event, context):
print("Hello World")
Run Code Online (Sandbox Code Playgroud)
我使用的是 macOS 10.X。在 Linux 上,我注意到 pip install 创建了一个单独的 confluence_kafka.libs,它不会在 mac 上创建
python amazon-web-services aws-lambda confluent-kafka-python
我有一个场景,我们在 Fargate 上有一些 AWS ECS 集群,并且 Secrets 从 Secrets Manager 和 AWS SSM 参数存储注入到这些任务定义中。现在,我们想要创建一个 Lambda 函数,以便在机密或参数更新时自动重新启动特定任务定义。我们创建了 AWS CloudWatch Log 组来创建日志(如果有更新),请删除本文档后面的密钥和参数: https://upstart.chrishic.com/updating-container-secrets-using-cloudwatch-events-lambda/
现在我们要实现一个 Lambda 函数,它将响应此 LogGroup 并验证密钥或参数的 ARN,并重新启动(执行强制部署)相应的 ECS 服务
在 AWS SAM .yaml 模板中,我可以为每个 lambda 函数声明一个内联策略,如下所示:
AWSTemplateFormatVersion: '2010-09-09'
Transform: 'AWS::Serverless-2016-10-31'
Resources:
MyFunction:
Type: 'AWS::Serverless::Function'
Properties:
Handler: index.handler
Runtime: nodejs8.10
CodeUri: 's3://my-bucket/function.zip'
Policies:
- Statement:
- Sid: SSMDescribeParametersPolicy
Effect: Allow
Action:
- ssm:DescribeParameters
Resource: '*'
- Sid: SSMGetParameterPolicy
Effect: Allow
Action:
- ssm:GetParameters
- ssm:GetParameter
Resource: '*'
Run Code Online (Sandbox Code Playgroud)
但是,如果我希望多个函数共享同一个内联策略文档,我们是否在模板的“全局”部分中声明它?
到目前为止,文档让我相信最干净的方法是创建一个带有附加策略的角色,然后简单地向每个函数声明该角色,如下所示:
AWSTemplateFormatVersion: '2010-09-09'
Transform: 'AWS::Serverless-2016-10-31'
Resources:
MyFunction:
Type: 'AWS::Serverless::Function'
Properties:
Handler: index.handler
Runtime: nodejs8.10
CodeUri: 's3://my-bucket/function.zip'
Role: arn:aws:iam::111111111111:role/SAMPolicy
Run Code Online (Sandbox Code Playgroud)
有没有办法在模板中声明内联策略并简单地在每个函数上引用它?
I'm trying to use AWS lambda to test a few API calls using axios, however I'm having some trouble. Every post I came across said the best way to handle promises in Lambda was to use async/await rather than .then, so I made the switch. When I run the program using node it works perfectly, but when I invoke the Lambda locally, it seems like everything after the axios call is being skipped. When I invoke the Lambda …
我尝试通过 zappa 更新 lambda,我创建了 virtualenv 和活动 virtualenv 并安装库,但在运行 zappa 更新环境时,我遇到了这个问题:\n我该如何解决这个问题:(
\n zappa update qa\n(pip 18.1 (/Library/Frameworks/Python.framework/Versions/3.6/lib/python3.6/site-packages), Requirement.parse('pip>=20.3'), {'pip-tools'})\nCalling update for stage qa..\nDownloading and installing dependencies..\nPackaging project as zip.\nUploading maximo-copy-customers-qa-1637639364.zip (6.0MiB)..\n100%|\xe2\x96\x88\xe2\x96\x88\xe2\x96\x88\xe2\x96\x88\xe2\x96\x88\xe2\x96\x88\xe2\x96\x88\xe2\x96\x88\xe2\x96\x88\xe2\x96\x88\xe2\x96\x88\xe2\x96\x88\xe2\x96\x88\xe2\x96\x88\xe2\x96\x88\xe2\x96\x88\xe2\x96\x88\xe2\x96\x88\xe2\x96\x88\xe2\x96\x88\xe2\x96\x88\xe2\x96\x88\xe2\x96\x88\xe2\x96\x88\xe2\x96\x88\xe2\x96\x88\xe2\x96\x88\xe2\x96\x88\xe2\x96\x88\xe2\x96\x88\xe2\x96\x88\xe2\x96\x88\xe2\x96\x88\xe2\x96\x88\xe2\x96\x88\xe2\x96\x88\xe2\x96\x88\xe2\x96\x88\xe2\x96\x88\xe2\x96\x88\xe2\x96\x88\xe2\x96\x88\xe2\x96\x88\xe2\x96\x88\xe2\x96\x88\xe2\x96\x88\xe2\x96\x88\xe2\x96\x88\xe2\x96\x88\xe2\x96\x88\xe2\x96\x88\xe2\x96\x88\xe2\x96\x88\xe2\x96\x88\xe2\x96\x88\xe2\x96\x88\xe2\x96\x88\xe2\x96\x88\xe2\x96\x88\xe2\x96\x88\xe2\x96\x88\xe2\x96\x88\xe2\x96\x88| 6.32M/6.32M [00:09<00:00, 664kB/s]\nUpdating Lambda function code..\nUpdating Lambda function configuration..\nOh no! An error occurred! :(\n\n==============\n\nTraceback (most recent call last):\n File "/Library/Frameworks/Python.framework/Versions/3.6/lib/python3.6/site-packages/zappa/cli.py", line 2778, in handle\n sys.exit(cli.handle())\n File "/Library/Frameworks/Python.framework/Versions/3.6/lib/python3.6/site-packages/zappa/cli.py", line 512, in handle\n self.dispatch_command(self.command, stage)\n File "/Library/Frameworks/Python.framework/Versions/3.6/lib/python3.6/site-packages/zappa/cli.py", line 559, in dispatch_command\n self.update(self.vargs['zip'], self.vargs['no_upload'])\n File "/Library/Frameworks/Python.framework/Versions/3.6/lib/python3.6/site-packages/zappa/cli.py", line 979, in update\n layers=self.layers\n File "/Library/Frameworks/Python.framework/Versions/3.6/lib/python3.6/site-packages/zappa/core.py", …Run Code Online (Sandbox Code Playgroud) aws-lambda ×10
node.js ×2
amazon-ecs ×1
amazon-rds ×1
amazon-sns ×1
amazon-sqs ×1
api-gateway ×1
async-await ×1
aws-sam ×1
boto3 ×1
python ×1
python-3.8 ×1
zappa ×1