尝试 运行 示例 "R on AWS Lambda with Containers"
Trying to run example "R on AWS Lambda with Containers"
我正在尝试 运行 MDNEUZERLING 创建的在 AWS Lambda 上使用 R 和容器的示例。
https://mdneuzerling.com/post/r-on-aws-lambda-with-containers/#fn:1
但是我在本地尝试 运行 时收到以下错误。 snip of error
07 Mar 2022 15:06:28,046 [INFO] (rapid) exec '/var/runtime/bootstrap' (cwd=/var/task, handler=)
07 Mar 2022 15:06:37,950 [INFO] (rapid) extensionsDisabledByLayer(/opt/disable-extensions-jwigqn8j) -> stat /opt/disable-extensions-jwigqn8j: no such file or directory
07 Mar 2022 15:06:37,950 [WARNING] (rapid) Cannot list external agents error=open /opt/extensions: no such file or directory
START RequestId: 8968dd09-4b03-4a0c-8260-202ac927ccb2 Version: $LATEST
Fatal error: cannot open file 'runtime.R': No such file or directory
07 Mar 2022 15:06:37,966 [WARNING] (rapid) First fatal error stored in appctx: Runtime.ExitError
07 Mar 2022 15:06:37,966 [WARNING] (rapid) Process 15(bootstrap) exited: Runtime exited with error: exit status 2
07 Mar 2022 15:06:37,966 [ERROR] (rapid) Init failed InvokeID= error=Runtime exited with error: exit status 2
07 Mar 2022 15:06:37,966 [WARNING] (rapid) Reset initiated: ReserveFail
07 Mar 2022 15:06:37,966 [WARNING] (rapid) Cannot list external agents error=open /opt/extensions: no such file or directory
Fatal error: cannot open file 'runtime.R': No such file or directory
07 Mar 2022 15:06:37,982 [WARNING] (rapid) First fatal error stored in appctx: Runtime.ExitError
07 Mar 2022 15:06:37,982 [WARNING] (rapid) Process 30(bootstrap) exited: Runtime exited with error: exit status 2
END RequestId: e7531a2a-1ca7-4975-9841-ff2d0beeeb18
REPORT RequestId: e7531a2a-1ca7-4975-9841-ff2d0beeeb18 Init Duration: 0.23 ms Duration: 31.98 ms Billed Duration: 32 ms Memory Size: 3
单独 shell 中的查询是:
curl -X POST "http://localhost:9000/2015-03-31/functions/function/invocations" -d "{'number': 5}"
我相信我是按照这个例子一步一步来的,但是有些地方做错了。
我的 dockerfile 如下:
FROM public.ecr.aws/lambda/provided:latest
ENV R_VERSION=4.0.3
RUN yum -y install wget
RUN yum -y install https://dl.fedoraproject.org/pub/epel/epel-release-latest-7.noarch.rpm \
&& wget https://cdn.rstudio.com/r/centos-7/pkgs/R-${R_VERSION}-1-1.x86_64.rpm \
&& yum -y install R-${R_VERSION}-1-1.x86_64.rpm \
&& rm R-${R_VERSION}-1-1.x86_64.rpm
ENV PATH="${PATH}:/opt/R/${R_VERSION}/bin/"
# System requirements for R packages
RUN yum -y install openssl-devel
RUN Rscript -e "install.packages(c('httr', 'jsonlite', 'logger'), repos = 'https://cloud.r-project.org/')"
#COPY runtime.R functions.R ${LAMBDA_TASK_ROOT}/
COPY runtime.r ${LAMBDA_TASK_ROOT}/
COPY functions.r ${LAMBDA_TASK_ROOT}/
RUN chmod 755 -R ${LAMBDA_TASK_ROOT}/
RUN printf '#!/bin/sh\ncd $LAMBDA_TASK_ROOT\nRscript runtime.R' > /var/runtime/bootstrap \
&& chmod +x /var/runtime/bootstrap
和functions.r文件如下:
#' Determine if the given integer is even or odd
#'
#' @param number Integer
#'
#' @return "even" or "odd"
#' @export
#'
#' @examples
#' parity(3) # odd
#' parity(4) # even
parity <- function(number) {
list(parity = if (as.integer(number) %% 2 == 0) "even" else "odd")
}
#' A nullary function that returns the current version of R
#'
#' @return character
#' @export
#'
#' @examples
#' hello()
hello <- function() {
list(response = paste("Hello from", version$version.string))
}
和 'runtime.R' 等同于:
https://github.com/mdneuzerling/r-on-lambda/blob/main/runtime.R
这是我第一次在这里提问,因此非常感谢您的反馈。我也坚持了几天,试图找出没有运气的问题。设法测试了一个工作正常的 python 示例,但确实需要使其与 R 一起工作。
问题出在 docker 文件中。在下面几行
COPY runtime.r ${LAMBDA_TASK_ROOT}/
COPY functions.r ${LAMBDA_TASK_ROOT}/
在原始文件中,这是按如下方式完成的,
COPY runtime.R functions.R ${LAMBDA_TASK_ROOT}/
这给了我一个错误,因此为每个要复制的文件制作了一行,但错误地将文件扩展名设置为小写,这造成了问题,因为 AWS 提供的图像正在寻找带有大写 R 扩展名的文件(我猜是这个),因为文件是用小写扩展名 '.r' 保存的。
我正在尝试 运行 MDNEUZERLING 创建的在 AWS Lambda 上使用 R 和容器的示例。 https://mdneuzerling.com/post/r-on-aws-lambda-with-containers/#fn:1
但是我在本地尝试 运行 时收到以下错误。 snip of error
07 Mar 2022 15:06:28,046 [INFO] (rapid) exec '/var/runtime/bootstrap' (cwd=/var/task, handler=)
07 Mar 2022 15:06:37,950 [INFO] (rapid) extensionsDisabledByLayer(/opt/disable-extensions-jwigqn8j) -> stat /opt/disable-extensions-jwigqn8j: no such file or directory
07 Mar 2022 15:06:37,950 [WARNING] (rapid) Cannot list external agents error=open /opt/extensions: no such file or directory
START RequestId: 8968dd09-4b03-4a0c-8260-202ac927ccb2 Version: $LATEST
Fatal error: cannot open file 'runtime.R': No such file or directory
07 Mar 2022 15:06:37,966 [WARNING] (rapid) First fatal error stored in appctx: Runtime.ExitError
07 Mar 2022 15:06:37,966 [WARNING] (rapid) Process 15(bootstrap) exited: Runtime exited with error: exit status 2
07 Mar 2022 15:06:37,966 [ERROR] (rapid) Init failed InvokeID= error=Runtime exited with error: exit status 2
07 Mar 2022 15:06:37,966 [WARNING] (rapid) Reset initiated: ReserveFail
07 Mar 2022 15:06:37,966 [WARNING] (rapid) Cannot list external agents error=open /opt/extensions: no such file or directory
Fatal error: cannot open file 'runtime.R': No such file or directory
07 Mar 2022 15:06:37,982 [WARNING] (rapid) First fatal error stored in appctx: Runtime.ExitError
07 Mar 2022 15:06:37,982 [WARNING] (rapid) Process 30(bootstrap) exited: Runtime exited with error: exit status 2
END RequestId: e7531a2a-1ca7-4975-9841-ff2d0beeeb18
REPORT RequestId: e7531a2a-1ca7-4975-9841-ff2d0beeeb18 Init Duration: 0.23 ms Duration: 31.98 ms Billed Duration: 32 ms Memory Size: 3
单独 shell 中的查询是:
curl -X POST "http://localhost:9000/2015-03-31/functions/function/invocations" -d "{'number': 5}"
我相信我是按照这个例子一步一步来的,但是有些地方做错了。
我的 dockerfile 如下:
FROM public.ecr.aws/lambda/provided:latest
ENV R_VERSION=4.0.3
RUN yum -y install wget
RUN yum -y install https://dl.fedoraproject.org/pub/epel/epel-release-latest-7.noarch.rpm \
&& wget https://cdn.rstudio.com/r/centos-7/pkgs/R-${R_VERSION}-1-1.x86_64.rpm \
&& yum -y install R-${R_VERSION}-1-1.x86_64.rpm \
&& rm R-${R_VERSION}-1-1.x86_64.rpm
ENV PATH="${PATH}:/opt/R/${R_VERSION}/bin/"
# System requirements for R packages
RUN yum -y install openssl-devel
RUN Rscript -e "install.packages(c('httr', 'jsonlite', 'logger'), repos = 'https://cloud.r-project.org/')"
#COPY runtime.R functions.R ${LAMBDA_TASK_ROOT}/
COPY runtime.r ${LAMBDA_TASK_ROOT}/
COPY functions.r ${LAMBDA_TASK_ROOT}/
RUN chmod 755 -R ${LAMBDA_TASK_ROOT}/
RUN printf '#!/bin/sh\ncd $LAMBDA_TASK_ROOT\nRscript runtime.R' > /var/runtime/bootstrap \
&& chmod +x /var/runtime/bootstrap
和functions.r文件如下:
#' Determine if the given integer is even or odd
#'
#' @param number Integer
#'
#' @return "even" or "odd"
#' @export
#'
#' @examples
#' parity(3) # odd
#' parity(4) # even
parity <- function(number) {
list(parity = if (as.integer(number) %% 2 == 0) "even" else "odd")
}
#' A nullary function that returns the current version of R
#'
#' @return character
#' @export
#'
#' @examples
#' hello()
hello <- function() {
list(response = paste("Hello from", version$version.string))
}
和 'runtime.R' 等同于:
https://github.com/mdneuzerling/r-on-lambda/blob/main/runtime.R
这是我第一次在这里提问,因此非常感谢您的反馈。我也坚持了几天,试图找出没有运气的问题。设法测试了一个工作正常的 python 示例,但确实需要使其与 R 一起工作。
问题出在 docker 文件中。在下面几行
COPY runtime.r ${LAMBDA_TASK_ROOT}/
COPY functions.r ${LAMBDA_TASK_ROOT}/
在原始文件中,这是按如下方式完成的,
COPY runtime.R functions.R ${LAMBDA_TASK_ROOT}/
这给了我一个错误,因此为每个要复制的文件制作了一行,但错误地将文件扩展名设置为小写,这造成了问题,因为 AWS 提供的图像正在寻找带有大写 R 扩展名的文件(我猜是这个),因为文件是用小写扩展名 '.r' 保存的。