我想知道如何访问我的 lambda 函数中引发的自定义异常的原因。我需要在 Step Functions 工作流程结束时访问它,如下所示。
下图是执行失败的示例。错误(error-info对象,有它自己Error和Cause部门)的输出被发现ParseTextractOutput,但我想知道如何访问它OutputNotFound,如下图所示。
的输出ParseTextractOutput是
{
"event"...
"error-info": {
"Error": "OutputNotFoundException",
"Cause": "{\"errorMessage\": \"Contents of Textracted file: {...}}"
}
}
}
Run Code Online (Sandbox Code Playgroud)
我想在这些字段(Step Functions 定义)中以某种方式访问这些数据:
...
"States": {
"OutputNotFound": {
"Type": "Fail",
"Error": "<useful stuff here, like $.error-info.Error or something>",
"Cause": "<useful stuff here, like $.error-info.Cause or something>"
},
...
"ParseTextractOutput": {
"Type": "Task",
"Resource": "functionARN",
"Catch": [
{
"ErrorEquals": ["OutputNotFoundException"],
"ResultPath": "$.error-info",
"Next": …Run Code Online (Sandbox Code Playgroud) python state-machine amazon-web-services aws-lambda aws-step-functions
我需要在Lambda(Python 3.7)中使用自己的boto3版本。Lambda默认Python 3.7 env(1.9.42)中包含的版本由于某种原因不支持使用Textract。
为此,我根据指南进行了以下操作:
pip freeze > requirements.txt 这将产生此文件:# requirements.txt
boto3==1.9.138
botocore==1.12.138
docutils==0.14
jmespath==0.9.4
python-dateutil==2.8.0
s3transfer==0.2.0
six==1.12.0
urllib3==1.24.2
Run Code Online (Sandbox Code Playgroud)
mkdir buildpip3 install -r requirements.txt -t build/cd buildzip -r ../boto3_layer.zip .然后,我使用GUI上传新的Lambda层(称为boto3Layer)。然后,将图层成功添加到Lambda函数中。
问题是,我不知道如何使用内联代码编辑器将所述层导入到我的代码中。
我有以下代码:
...
from boto3_layer as boto3
...
log.info(boto3)
Run Code Online (Sandbox Code Playgroud)
我得到错误 "errorMessage": "Unable to import module 'lambda_function': No module named 'boto3_layer'"
我也尝试导入just boto3,但是确认它是错误的版本(这是Lambda使用的版本),因此我的导入没有覆盖它。
我只想简单地知道如何将我的自定义层导入到我的代码中!谢谢
编辑:尝试建议:
virtualenv python --python=python3.7source python/bin/activate 然后 pip3 install boto3zip -r boto3_layer.zip python/lib/boto3_layer.zip并将其添加到Lambda函数 …python python-3.x aws-lambda python-packaging aws-lambda-layers
我正在使用适用于 Linux 的 Windows 子系统(Windows 10、Ubuntu 18.04 LTS)。我将在下面列出所有其他相关版本。
这个设置在我的 Mac 机器上工作,没有flags添加karma.conf.ts如下所示的阵列。
到目前为止,我已经看过:
Google Chrome 75.0.3770.80 HEADLESS 不再在 Docker 容器内工作
“重建”纱线使用 npm rebuild --update-binary
预期行为 启动 ChromeHeadless 并运行测试
当前行为yarn test按我通常的方式
运行会导致此错误:
02 10 2019 09:13:03.598:ERROR [launcher]: ChromeHeadless stdout:
02 10 2019 09:13:03.608:ERROR [launcher]: ChromeHeadless stderr: Failed to move to new namespace: PID namespaces supported, Network namespace supported, but failed: errno = Permission denied
Failed to …Run Code Online (Sandbox Code Playgroud) sls deploy -v && sls s3deploy像往常一样运行后,我遇到了这个问题:
...
CloudFormation - CREATE_FAILED - AWS::Logs::LogGroup - CallTextractLogGroup
...
CloudFormation - CREATE_FAILED - AWS::IAM::Role - IamRoleStateMachineExecution
CloudFormation - CREATE_FAILED - AWS::Logs::LogGroup - StartTextractStateMachineLogGroup
CloudFormation - CREATE_FAILED - AWS::Lambda::LayerVersion - Boto3LayerLambdaLayer
...
Serverless Error ---------------------------------------
An error occurred: StartTextractStateMachineLogGroup - /aws/lambda/textract-service-dev-startTextractStateMachine already exists.
Get Support --------------------------------------------
Docs: docs.serverless.com
Bugs: github.com/serverless/serverless/issues
Issues: forum.serverless.com
Your Environment Information ---------------------------
OS: linux
Node Version: 12.2.0
Serverless Version: 1.42.3
Run Code Online (Sandbox Code Playgroud)
我不记得在部署之前做任何更改,除了在Retry我的 Step Function States 中添加部分,这根本不应该与 CF 日志混淆。
我尝试运行 …
amazon-web-services aws-cloudformation aws-lambda amazon-cloudwatchlogs serverless
我想让变量可用于我的所有节点部署作业,以干燥我的 Gitlab 管道,但我也想提供依赖于每个单独作业的其他变量。当我处理需要唯一环境变量的多个节点服务时,这将有所帮助。
阅读文档,似乎有两种方法可以在.gitlab-ci.yml文件中执行此操作:
在 YAML 锚定定义中包含全局变量,希望它将与特定于作业的变量合并:
# anchor: global Node image deployment job
.deploy_node_image: &deploy_node_image
image: docker:latest
stage: deploy
services:
- docker:dind
variables: # global variables
REGION: "region"
ACCOUNT_ID: "id"
CLUSTER_NAME: "cluster"
script:
- apk add py-pip
- pip install awscli
- echo $CLUSTER_NAME $REGION $IMAGE_NAME $ACCOUNT_ID $SERVICE_NAME $SERVICE_DIR
- aws ecr get-login-password --region $REGION | docker login --username AWS
--password-stdin https://$ACCOUNT_ID.dkr.ecr.$REGION.amazonaws.com
- cd $CI_PROJECT_DIR/ingenio/new-backend/$SERVICE_DIR
- docker build
-t $ACCOUNT_ID.dkr.ecr.$REGION.amazonaws.com/$IMAGE_NAME:latest .
- docker push
$ACCOUNT_ID.dkr.ecr.$REGION.amazonaws.com/$IMAGE_NAME:latest
- …Run Code Online (Sandbox Code Playgroud) 我"errorMessage": "An error occurred (403) when calling the HeadObject operation: Forbidden"在尝试打电话时收到消息s3.download_file(请参阅下面的代码)。
我看过很多帖子,但似乎没有一个是从 AWS Lambda 调用的,而这正是我的问题所在。
我的代码在我的机器上本地运行,所以我猜测问题涉及 Lambda。这个Lambda函数最终会被S3事件触发,但在测试过程中,它不起作用。
我的 IAM 用户拥有对 S3 和 Lambda 的完全访问权限。
AWS Lambda函数代码:
import json
import boto3
import logging
log = logging.getLogger()
log.setLevel(logging.INFO)
s3 = boto3.client('s3')
def lambda_handler(event, context):
document_name = event['Records'][0]['s3']['object']['key']
bucket = event['Records'][0]['s3']['bucket']['name']
log.info('Performing stuff on {}/{}'.format(bucket, document_name))
# download the file
s3.download_file(
Bucket=bucket,
Key=document_name,
Filename=document_name
)
log.info('here it is!')
return event
Run Code Online (Sandbox Code Playgroud)
(我什至尝试显式输入信息s3.download_file而不是从 中获取信息event,但无济于事。日志消息确认它是正确的路径。)
测试事件配置中传递的参数:
...
"s3": …Run Code Online (Sandbox Code Playgroud) 我正在尝试按照AWS 文档和此在我的 CodeBuild 进程中运行一个小型 bash 脚本。
deploy.sh可以在目录中找到src/:
#!/bin/bash
pwd=$PWD
for dir in */ ; do
target="$pwd/${dir%/}"
cd "$target"
npm install
sls deploy && sls s3deploy
done
Run Code Online (Sandbox Code Playgroud)
构建规范文件:
version: 0.2
phases:
install:
runtime-versions:
nodejs: 10
commands:
- cd backend/functions/src
- npm install serverless
build:
commands:
- ls
- ./deploy.sh
Run Code Online (Sandbox Code Playgroud)
ls在日志中执行上述命令之后,我可以看到deploy.sh当前目录中存在该命令。
错误:
/codebuild/output/tmp/script.sh: 4: /codebuild/output/tmp/script.sh: ./deploy.sh: 未找到
我也尝试过使用该命令,/bin/bash deploy.sh但这会导致另一个错误:
deploy.sh:第 2 行:$'\r':找不到命令
deploy.sh:第 4 行:$'\r':找不到命令
deploy.sh:第 7 行:$'\r':找不到命令
deploy.sh:第 8 …
在 AWS Lambda 中,我的函数会将 S3 中的文件保存到/tmp目录中,如下所示:
local_filepath = '/tmp/file.txt'
s3.download_file(
Bucket=bucket,
Key=key,
Filename=local_filepath
)
Run Code Online (Sandbox Code Playgroud)
生活很好。
然而,使用 Serverless 是另一回事。
相同的设置会导致以下错误:
[Errno 2] No such file or directory: '/tmp/processed.txt.7E4850BD'
所以我猜想/tmp在无服务器执行环境中没有目录。
我试图将文件保存到当前目录,使用local_filepath = 'file.txt',但出现OSError(30, 'Read-only file system')错误。
python amazon-web-services aws-lambda serverless aws-serverless
aws-lambda ×5
python ×3
serverless ×2
amazon-iam ×1
amazon-s3 ×1
angular ×1
bash ×1
boto3 ×1
gitlab ×1
gitlab-ci ×1
karma-runner ×1
python-3.x ×1
yaml ×1