我使用运行时 Python 3.8 将以下代码部署到 AWS Lambda。
\n\ntry:\n raise Exception(\'my exception\')\nexcept Exception as e:\n raise ValueError(\'my exception 2\') from e\nRun Code Online (Sandbox Code Playgroud)\n\n在 CloudWatch 中,我希望看到像这样的异常链:
\n\nTraceback (most recent call last):\n File "/var/task/handler.py", line 2, in <module>\n raise Exception(\'my exception\')\nException: my exception\n\nThe above exception was the direct cause of the following exception:\n\nTraceback (most recent call last):\n File "/var/task/handler.py", line 4, in <module>\n raise ValueError(\'my exception 2\') from e\nValueError: my exception 2\nRun Code Online (Sandbox Code Playgroud)\n\n相反,我只看到 CloudWatch 中报告的第一个异常,如下所示:
\n\n[ERROR] ValueError: my exception 2\nTraceback …Run Code Online (Sandbox Code Playgroud) 我是 AWS 新手。我正在尝试使用 Lambda 函数连接到 AWS RDS postgreSQL 实例。我遵循了aws 文档。但它使用 python 来执行 Lambda 函数。下面是我的代码。
'use strict';
var pg = require('pg');
exports.handler = function (event, context) {
var dbConfig = {
username: '<username>',
password: '<password>',
database: '<database>',
host: '<db-endpoint>',
};
var client = new pg.Client(dbConfig);
try {
client.connect();
context.callbackWaitsForEmptyEventLoop = false;
client.end();
}
catch (err) {
console.log(err);
client.end();
}
};Run Code Online (Sandbox Code Playgroud)
我收到如下超时错误
START RequestId: 368e619e-ed9d-4241-93a5-764ee01aa847 Version: $LATEST
2020-06-15T16:28:18.911Z 368e619e-ed9d-4241-93a5-764ee01aa847 INFO connected
END RequestId: 368e619e-ed9d-4241-93a5-764ee01aa847
REPORT RequestId: 368e619e-ed9d-4241-93a5-764ee01aa847 Duration: 20020.16 ms …Run Code Online (Sandbox Code Playgroud) 我有一个 Lambda 函数,当消息发送到 SQS 队列时,它将发送 SNS 通知。但我观察到 Lambda 会在处理完消息后从队列中删除该消息,并且此处提到了这一点
有没有一种方法可以让 lambda 失败,而不用在 java.lang.String 中实际抛出新的异常。
我想创建一个 lambda 函数,每当创建新的 EC2 实例时都会触发该函数,此 Lambda 函数应自动在此新实例上配置 StatusCheck 警报。这样我就不必在每次创建新实例时手动配置 cloudwatch 警报。有人可以帮助编写完成此任务的 lambda 函数代码吗?
我有这样的事情:
response = client.put_metric_alarm(
AlarmName='StatusCheckFailed-Alarm-for-i-1234567890abcdef0',
AlarmActions=[
'arn:aws:sns:us-west-2:111122223333:my-sns-topic',
],
MetricName='StatusCheckFailed',
Namespace='AWS/EC2',
Statistic='Maximum',
Dimensions=[
{
'Name': 'InstanceId',
'Value': 'i-1234567890abcdef0'
},
],
Period=300,
Unit='Count',
EvaluationPeriods=2,
Threshold=1,
ComparisonOperator='GreaterThanOrEqualToThreshold')
Run Code Online (Sandbox Code Playgroud)
但我必须将 cloudwatch 规则中的实例 ID 作为输入映射到 Lambda。由于该函数会自动触发,因此无法每次手动输入实例 ID。
我正在使用 AWS Cloudfront 和 API 网关作为文件上传 API。我已将相同的代码部署到两个不同但相同的环境。这两个环境都是由相同的 cloudformation 脚本构建的。我们遇到了一个奇怪的问题
当我们在环境 A 中上传文件时,我们收到以下请求
"headers": {
"content-type": "multipart/form-data; boundary=----WebKitFormBoundarygPe3hR4e1dTzLdBt",
Run Code Online (Sandbox Code Playgroud)
然而,在环境中,BI 正在关注
"headers": {
"Content-Type": "multipart/form-data; boundary=----WebKitFormBoundarygPe3hR4e1dTzLdBt",
Run Code Online (Sandbox Code Playgroud)
区别在于内容类型。在环境 A 中,我得到小写的 Content-Type。不知道为什么。此行为在所有浏览器中都是一致的。
我在用着:
我正在连接到数据库,就像 github 中描述的那样,
const connection = await createConnection({
type: 'aurora-data-api-pg',
database: 'test-db',
secretArn: 'arn:aws:secretsmanager:eu-west-1:537011205135:secret:xxxxxx/xxxxxx/xxxxxx',
resourceArn: 'arn:aws:rds:eu-west-1:xxxxx:xxxxxx:xxxxxx',
region: 'eu-west-1'
})
Run Code Online (Sandbox Code Playgroud)
这就是我在 Lambda 函数中使用它的方式
export const testConfiguration: APIGatewayProxyHandler = async (event, _context) => {
let response;
try {
const connectionOptions: ConnectionOptions = await getConnectionOptions();
const connection = await createConnection({
...connectionOptions,
entities,
});
const userRepository = connection.getRepository(User);
const users = await userRepository.find();
response = {
statusCode: 200,
body: JSON.stringify({ users }),
}; …Run Code Online (Sandbox Code Playgroud) aws-lambda serverless-framework typeorm aws-aurora-serverless
我在 python 2.7 运行时环境上有大约 13 个带有触发器的 Lambda 函数。我需要更新到3.6
做到这一点最有效的方法是什么?我需要创建所有新的 lambda 表达式吗?如果出现问题,我可以回滚到 2.7 lambda 吗?
任何帮助将不胜感激。
我有一个带有 SSR 的 Next.js 应用程序,它依赖于环境变量。当我将应用程序部署到 AWS Amplify 时,会创建 2 个 Lambda 函数。
我在 Amplify 中设置了环境变量,但是,这些变量未在构建期间创建的 Lambda 函数中设置。如果我在函数上手动设置环境变量,它们将在下一次构建期间被删除。
关于这应该如何运作有什么想法吗?
我无法使用 Node.js 连接到 redshift 数据库。我正在使用 Node JS 版本14.15.1。这个版本有什么问题吗?
以下代码,我在我的本地机器上尝试过,
redshift.js文件
var Redshift = require('node-redshift');
var client = {
user: 'user',
database: 'db',
password: 'password',
port: port,
host: 'hostname',
};
var redshiftClient = new Redshift(client, {rawConnection:true});
module.exports = redshiftClient;
Run Code Online (Sandbox Code Playgroud)
index.js以下是从数据库、文件中获取值的代码
var redshiftClient = require('./redshift.js');
console.log('Before Connection');
redshiftClient.connect(function(err){
console.log('After Connection');
if(err) throw err;
else{
redshiftClient.query('SELECT * FROM "customer"', {raw: true}, function(err, data){
if(err) throw err;
else{
console.log(data);
redshiftClient.close();
}
});
}
});
Run Code Online (Sandbox Code Playgroud)
如果我运行这段代码没有得到错误,甚至这一行也没有被执行console.log('After Connection');
我有一个 AWS lambda 程序在日志中收到此警告:
/var/task/requests/ init .py:89: RequestsDependencyWarning: urllib3 (1.26.6) 或 chardet (3.0.4) 与支持的版本不匹配!
我已经尝试过其他线程中提到的修复(例如此线程),但无法解决此问题
奇怪的是,在我的 virtualenv 中,我有:
chardet==4.0.0
urllib3==1.25.10
Run Code Online (Sandbox Code Playgroud)
...但警告抱怨 chardet 3.0.4 和 urllib 1.26.6。想知道这是否与 AWS Lambda 环境提供的包有关。我假设我的包会覆盖它们的默认值。
aws-lambda ×10
node.js ×2
python-3.x ×2
amazon-rds ×1
amazon-sqs ×1
api ×1
automation ×1
aws-amplify ×1
java ×1
next.js ×1
postgresql ×1
python-2.7 ×1
typeorm ×1