AWS lambda上的纱线?

发布于 2025-01-28 01:37:06 字数 2326 浏览 1 评论 0原文

是否有人设法获得 yarn 安装并在AWS lambda上工作?

(我正在尝试创建一个可以构建小反应项目的函数)

目前,我已经在Docker映像中安装了纱线并工作(基于public.ecr.aws/lambda/provided:al2),但是在Lambda中运行它时纱线试图访问只读文件系统时,我会遇到权限错误。

Dockerfile摘要:

FROM public.ecr.aws/lambda/provided:al2
...
# Update yum
RUN yum -y update
# Install NodeJS
RUN curl -fsSL https://rpm.nodesource.com/setup_16.x \
    | bash - && yum -y install nodejs
# Install Yarn
RUN curl -fsSL https://dl.yarnpkg.com/rpm/yarn.repo \
    | tee /etc/yum.repos.d/yarn.repo && \
    rpm --import https://dl.yarnpkg.com/rpm/pubkey.gpg && \
    yum -y install yarn
# Copy Binaries
RUN cp -r \
    /usr/share/yarn/bin/* \
    /usr/bin/corepack /usr/bin/node /usr/bin/npm /usr/bin/npx \
    /opt/bin/
# Copy Libraries
RUN cp -r \
    /usr/share/yarn/lib/* \
    /usr/lib/node_modules \
    /opt/lib/
# Configure NPM & Yarn
RUN npm config set prefix /tmp/npm/
RUN yarn config set prefix /tmp/yarn/
...

错误:

>yarn install
warning Cannot find a suitable global folder. Tried these: "/usr/local, /home/sbx_user1051/.yarn"
ovl: Error while doing RPMdb copy-up:
[Errno 30] Read-only file system: '/var/lib/rpm/.dbenv.lock'
Could not set cachedir: [Errno 30] Read-only file system: '/var/tmp/yum-sbx_user1051-eC5Oqk'
Error making cache directory: /var/cache/yum/x86_64/2/amzn2-core error was: [Errno 30] Read-only file system: '/var/cache/yum'
error Command failed with exit code 1.

***编辑***

带有全局标志

>yarn --global-folder /tmp/yarn/ install
warning Skipping preferred cache folder "/home/sbx_user1051/.cache/yarn" because it is not writable.
warning Selected the next writable cache folder in the list, will be "/tmp/.yarn-cache-993".
warning Cannot find a suitable global folder. Tried these: "/usr/local, /home/sbx_user1051/.yarn"
ovl: Error while doing RPMdb copy-up:
[Errno 30] Read-only file system: '/var/lib/rpm/.dbenv.lock'
Could not set cachedir: [Errno 30] Read-only file system: '/var/tmp/yum-sbx_user1051-3FcZxd'
Error making cache directory: /var/cache/yum/x86_64/2/amzn2-core error was: [Errno 30] Read-only file system: '/var/cache/yum'
error Command failed with exit code 1.

Did anyone manage to get yarn installed and working on AWS Lambda?

(I'm trying to create a function that can build small React projects)

Currently I have yarn installed and working in a Docker image (based on public.ecr.aws/lambda/provided:al2), but while running it in the Lambda environment I'm getting permission errors when yarn tries to access the read-only file system.

Dockerfile snippet:

FROM public.ecr.aws/lambda/provided:al2
...
# Update yum
RUN yum -y update
# Install NodeJS
RUN curl -fsSL https://rpm.nodesource.com/setup_16.x \
    | bash - && yum -y install nodejs
# Install Yarn
RUN curl -fsSL https://dl.yarnpkg.com/rpm/yarn.repo \
    | tee /etc/yum.repos.d/yarn.repo && \
    rpm --import https://dl.yarnpkg.com/rpm/pubkey.gpg && \
    yum -y install yarn
# Copy Binaries
RUN cp -r \
    /usr/share/yarn/bin/* \
    /usr/bin/corepack /usr/bin/node /usr/bin/npm /usr/bin/npx \
    /opt/bin/
# Copy Libraries
RUN cp -r \
    /usr/share/yarn/lib/* \
    /usr/lib/node_modules \
    /opt/lib/
# Configure NPM & Yarn
RUN npm config set prefix /tmp/npm/
RUN yarn config set prefix /tmp/yarn/
...

Errors:

>yarn install
warning Cannot find a suitable global folder. Tried these: "/usr/local, /home/sbx_user1051/.yarn"
ovl: Error while doing RPMdb copy-up:
[Errno 30] Read-only file system: '/var/lib/rpm/.dbenv.lock'
Could not set cachedir: [Errno 30] Read-only file system: '/var/tmp/yum-sbx_user1051-eC5Oqk'
Error making cache directory: /var/cache/yum/x86_64/2/amzn2-core error was: [Errno 30] Read-only file system: '/var/cache/yum'
error Command failed with exit code 1.

*** edit ***

With global flag

>yarn --global-folder /tmp/yarn/ install
warning Skipping preferred cache folder "/home/sbx_user1051/.cache/yarn" because it is not writable.
warning Selected the next writable cache folder in the list, will be "/tmp/.yarn-cache-993".
warning Cannot find a suitable global folder. Tried these: "/usr/local, /home/sbx_user1051/.yarn"
ovl: Error while doing RPMdb copy-up:
[Errno 30] Read-only file system: '/var/lib/rpm/.dbenv.lock'
Could not set cachedir: [Errno 30] Read-only file system: '/var/tmp/yum-sbx_user1051-3FcZxd'
Error making cache directory: /var/cache/yum/x86_64/2/amzn2-core error was: [Errno 30] Read-only file system: '/var/cache/yum'
error Command failed with exit code 1.

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。
列表为空,暂无数据
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文