我有一个简单的项目。基本设置是这样的......
project
|- etc
| |- sam.yaml
| \- swagger.yaml
|- src
| |- client
| | \- Client files (VUE frontend)
| \- backend
| |- index.js
| \- package.json
\- gulpfile.js
Run Code Online (Sandbox Code Playgroud)
我运行 gulp,最终得到一个build文件夹。它看起来像这样......
build
|- client
| |- index.html
| \- More static client files
|- backend
| |- index.js
| |- package.json
| \_ node_modules
| \- Lots of stuff
\- backend.zip
Run Code Online (Sandbox Code Playgroud)
构建效果很好。我想在本地运行它,而不是每次进行更改时都将 ZIP 上传到 lambda,将客户端目录上传到 S3。
为此,我正在运行aws-sam-local。是的,我已经docker安装并运行。从项目文件夹中我运行这个...
sam local start-api …Run Code Online (Sandbox Code Playgroud) 根据 AWS 文档,我将像这样启动本地 SAM:
$ sam local start-api -d 5858
Run Code Online (Sandbox Code Playgroud)
我的 launch.json 中有以下内容
{
"version": "0.2.0",
"configurations": [
{
"name": "Attach to SAM Local",
"type": "node",
"request": "attach",
"address": "localhost",
"port": 5858,
"localRoot": "${workspaceRoot}",
"remoteRoot": "/var/task"
}
]
}
Run Code Online (Sandbox Code Playgroud)
但是当我启动 Visual Studio 调试器时,它说“无法连接到运行时,请确保运行时处于‘旧版’调试模式”
看起来很多人都在使用 Node.js 6 和 Visual Studio Code 时遇到这个问题,但我似乎找不到答案......我正在使用 Visual Studio Code 版本 1.18.1
我尝试将 "protocol": "Legacy" 添加到 launch.json 配置。我还尝试使用 --debug-port 而不是 -d 。我使用的是 Windows 10。不确定问题是否特定于 Windows。
当尝试使用 AWS SAM CLI 部署到 AWS 时,我的 Lambda 函数使用以下脚本:
aws cloudformation deploy --template-file /Users/ndelvalle/Projects/foo/functions/packaged-template.yaml --stack-name foo --region sa-east-1 --capabilities CAPABILITY_IAM --no-fail-on-empty-changeset
Run Code Online (Sandbox Code Playgroud)
我在堆栈事件中收到以下错误:
API: iam:CreateRole User: arn:aws:iam::user/nico is not authorized to perform: iam:CreateRole on resource
Run Code Online (Sandbox Code Playgroud)
这是因为我的帐户没有角色创建权限。这就是为什么我想知道是否有一种方法可以为我的 lambda 定义预先创建的角色,这样脚本就不需要创建角色。
使用该sam build命令时,我预计不会包含该aws-sdk包,因为 Node.js Lambda 运行时已包含该包。
据我了解, for nodejs 是来自命令sam build的端口,但是当我运行时我没有看到任何标志。claudia packclaudiajs--no-optional-dependenciessam build --help
我尝试安装aws-sdk为可选依赖项,但仍然包含在内。
有没有办法node_modules使用sam build命令从目录中排除依赖项?
我正在用来AWS SAM部署我的 lambda 和 api 网关。下面是我的模板 yaml 文件:
AWSTemplateFormatVersion: '2010-09-09'
Transform: AWS::Serverless-2016-10-31
Description: >
sam-app
Sample SAM Template for sam-app
# More info about Globals: https://github.com/awslabs/serverless-application-model/blob/master/docs/globals.rst
Globals:
Function:
Timeout: 3
Resources:
HelloWorldFunction:
Type: AWS::Serverless::Function # More info about Function Resource: https://github.com/awslabs/serverless-application-model/blob/master/versions/2016-10-31.md#awsserverlessfunction
Properties:
CodeUri: hello-world/
Handler: app.lambdaHandler
Runtime: nodejs8.10
Events:
HelloWorld:
Type: Api # More info about API Event Source: https://github.com/awslabs/serverless-application-model/blob/master/versions/2016-10-31.md#api
Properties:
Path: /hello
Method: post
Outputs:
# ServerlessRestApi is an implicit API created out of Events key under …Run Code Online (Sandbox Code Playgroud) amazon-web-services aws-cloudformation aws-api-gateway aws-sam-cli
以下是 aws sam 的 Dockerfile:
FROM buildpack-deps:stable
ARG PYTHON_VERSION=3.7.4
# Update and allow for apt over HTTPS
RUN apt-get update && \
apt-get install -y apt-utils
RUN apt-get install -y apt-transport-https
# download and build Python 3.7, install basic Python libraries
# (this predates pipenv so a mixture of dependencies)
ADD requirements.txt /requirements.txt
RUN cd /usr/src && \
wget https://www.python.org/ftp/python/${PYTHON_VERSION}/Python-${PYTHON_VERSION}.tgz && \
tar xzf Python-${PYTHON_VERSION}.tgz && \
cd Python-${PYTHON_VERSION} && \
./configure --enable-optimizations && \
make altinstall && \
apt-get …Run Code Online (Sandbox Code Playgroud) 我一直在学习 AWS SAM 的诀窍,并成功部署了许多 lambda 表达式以及依赖项和其他 AWS 服务。但是,在尝试部署依赖于某些特定依赖项的 lambda 时,我似乎遇到了问题。
这是我的requirements.txt 文件:
paramiko==2.4.2
cryptography==2.6.1
bcrypt==3.1.6
pynacl==1.3.0
Run Code Online (Sandbox Code Playgroud)
该文件位于“packageRoot/myCodeUri/requirements.txt”中
当我运行 sam build 时,出现以下错误:
2019-08-27 11:18:18 Running PythonPipBuilder:ResolveDependencies
Build Failed
Error: PythonPipBuilder:ResolveDependencies - {pynacl==1.3.0(wheel), cryptography==2.6.1(wheel), bcrypt==3.1.6(wheel)}
Run Code Online (Sandbox Code Playgroud)
此(或至少类似)错误已报告: 8 个多月前,但目前尚未得到答复。
PS 我最初只用 paramiko 尝试过这个,因为据我了解,这是我的脚本使用的唯一库;依赖项应该在构建过程中自动引入,但这也不起作用。
任何帮助都会很棒吗?
我对 AWS lambda 和 SAM 比较陌生,现在我已经可以正常工作了,但我有一个看似简单的问题,但找不到答案。
上周我使用 SAM 启动并运行了一个 lambda 应用程序(多次构建、打包、部署,直到它正常工作)。
所以现在我用来上传的 S3 存储桶有许多(大约 100 个)之前(由sam package)上传的我的压缩代码版本。
sam package上传新版本时自动删除软件包的旧版本?在我用来存储 lambda 包的存储桶中,我还有一个自定义层。
因此,如果只是应用程序包,我可以轻松地(现在)进入并删除存储桶中的所有内容,然后进行重新构建/打包/部署来清理它。...但这也会删除我的图层(并且 - 同样的问题 - 我现在确定该图层正在使用存储桶中的哪个 zip 文件)。
但这种方法从长远来看是行不通的,因为我计划将大约 10-15 个不同的包/函数放在一起,因此在仅更新其中一个包/函数时删除存储桶中的所有内容是行不通的。
感谢您的任何想法、想法和帮助!
我在我的 Nodejs 服务器上使用 ES6 模块语法:
包.json
"type": "module"
Run Code Online (Sandbox Code Playgroud)
我(成功)将我的服务器作为本地 Nodejs 进程运行。例如:
"scripts": {
"dev": "npm outdated ; nodemon --experimental-modules --inspect=4001 main.local.js"
}
Run Code Online (Sandbox Code Playgroud)
问题:如果我通过 sam local 启动服务器:
"scripts": {
"dev-sam": "sam local start-api --skip-pull-image",
}
Run Code Online (Sandbox Code Playgroud)
我收到错误:
Warning: require() of ES modules is not supported.
require() of /var/task/main.js from /var/runtime/UserFunction.js is an ES module file
as it is a .js file whose nearest parent package.jsoncontains "type": "module" which
defines all .js files in that package scope as ES modules.
Instead rename main.js …Run Code Online (Sandbox Code Playgroud) aws-sam-cli ×10
aws-sam ×4
aws-lambda ×2
debugging ×1
docker ×1
dockerfile ×1
es6-modules ×1
javascript ×1
lambda ×1
node.js ×1
paramiko ×1
python ×1