我是 Nodejs 新手。我将一个 zip 文件从 S3 存储桶保存到托管 Nodejs 服务的 EC2 实例,然后在 EC2 的文件系统中本地解压缩该 zip 文件:
const s3Item = await S3.getFile(objectBucket, objectKey);
let stream = s3Item.Body.pipe(fs.createWriteStream(sourceFilePath, { mode: 0o777 }));
stream.on('finish', () => {
logger.info(` pipe done `);
});
logger.info(`start decompressing...`);
await decompressArchive(sourceFilePath, targetDirectory_decompressed);
... a lot of code...
Run Code Online (Sandbox Code Playgroud)
但是,start decompressing...
总是在pipe done
打印之前打印。
如何使这两个步骤同步,以便我们等到pipe done
,然后开始解压缩?
我想使用 async/await ,因为我根本无法将所有其余代码放入块中stream.on('finish', () => {});
,因为代码太多,并且它们都依赖于正在完成的流。
我已经搜索了相关答案(其中有很多),但我仍然无法使其工作。
我正在尝试使用 AWS Cognito 作为 AWS API Gateway 中的 REST API 的授权者。
它要求我填写Issuer URL
:
深入研究AWS Cognito用户池页面,发现根本没有这样的事情。
我在这里找到了相关的答案:AWS:Cognito与API网关中的测试版HTTP API集成? 我引用:
Issuer URL: Check the metadata URL of your Cognito User Pool
(construct the URL in this format :: https://cognito-idp.
[region].amazonaws.com/[userPoolId]/.well-known/openid-configuration
:: look for a claim named "issuer". Copy its Value and paste it here.
Run Code Online (Sandbox Code Playgroud)
我当然可以如上所述构建 url。
但仍然,哪里是metadata URL of my Cognito User Pool
???
我问这个问题是否错过了一些非常基本的东西并且绝对愚蠢?
它在哪里??
这真让我抓狂。
我正在将 AWS Amplify / AWS Cognito 用于我的 Web 应用程序。它会自动将令牌放入浏览器的本地存储中。这是 SDK 的预期行为。它将令牌添加到本地存储中,以便用户可以在会话关闭然后重新启动后使用该应用程序,而无需再次登录。
但是,在我奇怪的用户场景中,我必须制作我的网络应用程序,以便当用户关闭浏览器并重新打开它时,用户必须再次登录。
因此,我不需要将令牌保存在 localStorage 中,而是需要将它们保存在 Web 浏览器的 sessionStorage 中。
怎样做才好看呢?
session-storage amazon-web-services local-storage jwt amazon-cognito
我已按照此 AWS 博客使用电子邮件 TOTP(基于时间的一次性密码)作为 MFA 为我的网站实施自定义身份验证流程: https ://aws.amazon.com/blogs/mobile/extending-amazon-cognito-with -email-otp-for-2fa-using-amazon-ses/
基本上它解释了在 Cognito 上如何使用CUSTOM_CHALLENGE
和 3 lambda 函数来:
这样我们就可以达到与基于短信的 MFA 相同的效果,只不过代码是作为电子邮件而不是手机上的短信发送的。
请注意,这与 Cognito 用户池设置中的“MFA”部分非常不同:
上述 MFA 适用于手机短信。
遵循博客教程后,我的工作进展顺利。
但是我有两个问题,在网上找不到解决方案:
如何设置发送到用户电子邮件的一次性密码的过期时间?\
我确信有一个过期时间,并且我相信它是 10 分钟,但文档却找不到。
如何允许 cognito 记住该设备,以便仅当用户尝试从与之前设备不同的设备登录时才需要将电子邮件 TOTP 作为第二因素?
对于 Cognito 设置上基于文本消息的 MFA(或“真正的”MFA),只需在“设备”部分启用即可轻松实现:
Do you want to use a remembered device to suppress the second factor during multi-factor authentication (MFA)?
Run Code Online (Sandbox Code Playgroud)
但是,对于为 2FA 实现电子邮件 OTP 的方法,我该如何执行此操作?
amazon-web-services amazon-cognito multi-factor-authentication
我真的对tf.estimator.inputs.numpy_input_fn
这里的tensorflow估计器的文档感到困惑,尤其是关于以下内容的行num_epochs
:
num_epochs: Integer, number of epochs to iterate over data. If None will run forever.
如果我设置num_epochs
到None
,培训会永远运行下去?
它永远运行意味着什么?
这对我来说没有意义,因为我无法想象人们会以可能永远运行的方式设计程序。
有人可以解释吗?
回答我自己的问题:我想我已经在这里找到答案了:https : //www.tensorflow.org/versions/r1.3/get_started/input_fn#evaluating_the_model
具体来说,在该部分中Building the input_fn
:
Two additional arguments are provided: num_epochs: controls the number of epochs to iterate over data. For training, set this to None, so the
input_fn keeps returning data until the required number of train steps is reached. For evaluate and predict, set this to …
文献称MCMC中的metropolis-hasting算法是上世纪发展起来的最重要的算法之一,具有革命性。文献还说,正是 MCMC 的这种发展给了贝叶斯统计第二次诞生。
我了解 MCMC 的作用 - 它提供了一种从任何复杂概率分布中抽取样本的有效方法。
我也知道贝叶斯推理是什么——它是计算参数的完整后验分布的过程。
我很难在这里连接点:MCMC 在贝叶斯推理过程中的哪一步发挥作用?为什么 MCMC 如此重要以至于人们说是 MCMC 给了贝叶斯统计第二次出生?
我正在使用 MacOS 并正在开发一个 python 项目。在我的项目中有一行:
num_workers = int(os.environ.get('NUM_SAS_WORKERS', 1))
Run Code Online (Sandbox Code Playgroud)
我想添加NUM_SAS_WORKERS
我的环境变量并将其设置为 10,以便我的 python 项目可以将值 10 加载到num_workers
我尝试在终端中执行此操作:
export NUM_SAS_WORKERS=10
Run Code Online (Sandbox Code Playgroud)
我能够NUM_SAS_WORKERS = 10
通过printenv
在终端中运行来验证它是否存在
但这不起作用。在我的Python脚本中num_workers
仍然加载了1
怎样做才正确呢?
https://typeorm.io/#/select-query-builder/how-to-create-and-use-a-querybuilder
创建查询生成器的方法有多种:
使用连接:
import {getConnection} from "typeorm";
const user = await getConnection()
.createQueryBuilder()
.select("user")
.from(User, "user")
.where("user.id = :id", { id: 1 })
.getOne();
Run Code Online (Sandbox Code Playgroud)
使用实体管理器:
import {getManager} from "typeorm";
const user = await getManager()
.createQueryBuilder(User, "user")
.where("user.id = :id", { id: 1 })
.getOne();
Run Code Online (Sandbox Code Playgroud)
使用存储库:
import {getRepository} from "typeorm";
const user = await getRepository(User)
.createQueryBuilder("user")
.where("user.id = :id", { id: 1 })
.getOne();
Run Code Online (Sandbox Code Playgroud)
该文档从未解释这些方法之间的区别。每种方法什么时候使用?
我正在将 AWS Cognito 用于我的 Web 应用程序。
\n我登录到我的网络应用程序并从浏览器开发模式获取访问/刷新令牌。
\n访问令牌可以在https://jwt.io/上解码上解码:
\n标题是
\n{\n "kid": "M+aYDxi5AeOrvlUkPyNA5GmA4V8ZdTPPnr5wO6M1neU=",\n "alg": "RS256"\n}\n\n
Run Code Online (Sandbox Code Playgroud)\n有效负载为:
\n{\n "origin_jti": "0cf3100a-bfdd-49e0-bae3-12345678",\n "sub": "1585d704-2985-4447-b265-12345678",\n "event_id": "ead55f68-59d0-4b7f-9bb8-123",\n "token_use": "access",\n "scope": "aws.cognito.signin.user.admin",\n "auth_time": 1646640361,\n "iss": "https://cognito-idp.ap-northeast-1.amazonaws.com/ap-northeast-1_123",\n "exp": 1646640661,\n "iat": 1646640361,\n "jti": "ea239510-8fd4-497d-b2ac-05a0377d63ef",\n "client_id": "123qwe",\n "username": "staff"\n}\n\n
Run Code Online (Sandbox Code Playgroud)\n但是,刷新令牌未正确解码:\n标头:
\n{\n "cty": "JWT",\n "enc": "A256GCM",\n "alg": "RSA-OAEP"\n}\n
Run Code Online (Sandbox Code Playgroud)\n有效负载是:
\n"v\xef\xbf\xbdzsV_%\xef\xbf\xbd\xef\xbf\xbd\xef\xbf\xbd\xef\xbf\xbd\xef\xbf\xbd\xef\xbf\xbd$\xef\xbf\xbd\xef\xbf\xbd\\u0014\xef\xbf\xbd\xef\xbf\xbd\xef\xbf\xbd1\xef\xbf\xbd\xef\xbf\xbdZ\xef\xbf\xbdc\xef\xbf\xbd\xef\xbf\xbd\xef\xbf\xbdhyE\xef\xbf\xbd\\u0000\xef\xbf\xbd\\u0001\xef\xbf\xbd9W\xef\xbf\xbd\xef\xbf\xbd\xef\xbf\xbd\xef\xbf\xbdG\xef\xbf\xbd5\xef\xbf\xbd\xef\xbf\xbd\xef\xbf\xbd\\n\\n\xd2\xb4\xef\xbf\xbd\\t!8Mc\\u0000~3}K\xef\xbf\xbd4\xef\xbf\xbd\xef\xbf\xbdX=\\"\xef\xbf\xbd%\\u0015\xef\xbf\xbd2\xef\xbf\xbd\\"S,\xef\xbf\xbd\xef\xbf\xbdM\xef\xbf\xbd\xef\xbf\xbd\\u0000=S\xef\xbf\xbd\\u0011r\xef\xbf\xbd*H9\xef\xbf\xbd}\\u0002\xef\xbf\xbd\xef\xbf\xbdt]\xef\xbf\xbdxU\'\xef\xbf\xbdLk\xef\xbf\xbd\xef\xbf\xbdN\xee\xad\xa2\\n\xef\xbf\xbdxB\xef\xbf\xbdYg\xef\xbf\xbd`\xef\xbf\xbdm\xef\xbf\xbd\\n\xef\xbf\xbd_\xef\xbf\xbdey\xef\xbf\xbd\xef\xbf\xbdj\xef\xbf\xbdo\xef\xbf\xbd\xef\xbf\xbd\xef\xbf\xbd_\xef\xbf\xbdlJ\xef\xbf\xbde^\xef\xbf\xbdh\\n=\xef\xbf\xbd\\u001a\xef\xbf\xbdV7\xef\xbf\xbd!\xef\xbf\xbd]\xef\xbf\xbd5A\\u0014\\u0012(3\xef\xbf\xbd\xef\xbf\xbdi(mu\xef\xbf\xbd\xef\xbf\xbd\xef\xbf\xbd\\u0018\xef\xbf\xbdc\xef\xbf\xbdY\xef\xbf\xbd\xef\xbf\xbd\xef\xbf\xbd\xd7\x81\xef\xbf\xbd\xef\xbf\xbd.VC\xef\xbf\xbd\xef\xbf\xbd3\xef\xbf\xbdyk6\xef\xbf\xbd\xef\xbf\xbd$b\xef\xbf\xbdX\xef\xbf\xbd5\xef\xbf\xbdC\xef\xbf\xbdQ\xef\xbf\xbd/\xef\xbf\xbd\xef\xbf\xbd\xef\xbf\xbd)\xef\xbf\xbd\xef\xbf\xbd\xef\xbf\xbd=\\u001b|a\xef\xbf\xbd\\u000b\\f\xef\xbf\xbd\\u0015/\\u0005\\u00057\xef\xbf\xbd\xef\xbf\xbd\xef\xbf\xbd\xef\xbf\xbda\xdf\xa8`\xef\xbf\xbdB\xef\xbf\xbd.\xef\xbf\xbd\\u000f\xef\xbf\xbd(]\xef\xbf\xbd\\\\\xef\xbf\xbd\\u0007G\xef\xbf\xbd"\n
Run Code Online (Sandbox Code Playgroud)\n看起来刷新令牌的算法是RSA-OAEP
https://jwt.io/站点尚不支持此算法。
是否有在线工具可以正确解码刷新令牌?
\njwt ×2
async-await ×1
bayesian ×1
bitbucket ×1
git ×1
macos ×1
mcmc ×1
montecarlo ×1
multi-factor-authentication ×1
node.js ×1
oauth ×1
python ×1
statistics ×1
stream ×1
tensorflow ×1
terminal ×1
token ×1
typeorm ×1
typescript ×1