Add mount option on sam local invoke/start-api
- Dominant language
- Python
- Stars
- 6.7k
- Forks
- 1.2k
- Avg merge
- 1d 10h
- Merged PRs (30d)
- 52
Description
### Describe your idea/feature/enhancement
Related to:
- https://github.com/aws/aws-sam-cli/pull/1486/files
- https://github.com/aws/aws-sam-cli/issues/1896
- https://github.com/aws/aws-sam-cli/issues/1485
We use custom lambda container images. We run code in `/var/task/` or mount from EFS and run in `/mnt/*`.
We can't emulate the `/mnt` mount with SAM, or make changes to code mounted in `/var/task` without a rebuild. This complicates dev - and makes dev impossible for builds with a big codebase.
The lambda runtime emulator works but is very limited.
Is there a workaround?
### Proposal
It would be great to emulate the behaviour of docker --mount, with an extra function param:
From the example below:
```
sam local start-api --mount func=MyFunc,source="$(pwd)"/code,target=/mnt/shop
```
### Additional Details
#### Example
```
- code/
-- foo.php
- bootstrap
- Dockerfile
- template.yaml
```
foo.php
```php
false,
'statusCode' => 200,
'body' => '{"abc":123}'
]
);
```
bootstrap
```bash
#!/bin/bash
set -euo pipefail
while true
do
HEADERS="$(mktemp)"
EVENT_DATA=$(curl -sS -LD "$HEADERS" -X GET "http://${AWS_LAMBDA_RUNTIME_API}/2018-06-01/runtime/invocation/next")
REQUEST_ID=$(grep -Fi Lambda-Runtime-Aws-Request-Id "$HEADERS" | tr -d '[:space:]' | cut -d: -f2)
RESPONSE="$(mktemp)"
export EVENT_DATA
php /mnt/shop/foo.php >> "${RESPONSE}"
curl -sS -X POST "http://${AWS_LAMBDA_RUNTIME_API}/2018-06-01/runtime/invocation/${REQUEST_ID}/response" -d @${RESPONSE}
done
```
Dockerfile
```Dockerfile
FROM amazon/aws-lambda-provided:al2 as base
RUN yum install -y amazon-linux-extras
RUN amazon-linux-extras install epel -y
RUN rpm -Uvh http://rpms.remirepo.net/enterprise/remi-release-7.rpm
RUN yum --enablerepo=remi-php74 install -y \
php-cli-7.4.14
COPY bootstrap /var/runtime
RUN chmod 755 /var/runtime/bootstrap
CMD [ "handler.php" ]
```
template.yaml
```yaml
AWSTemplateFormatVersion: '2010-09-09'
Transform: AWS::Serverless-2016-10-31
Resources:
FileSystem:
Type: AWS::EFS::FileSystem
Properties: []
MountTarget:
Type: AWS::EFS::MountTarget
Properties: []
AccessPoint:
Type: AWS::EFS::AccessPoint
Properties: []
MyFunc:
Type: AWS::Serverless::Function
Metadata:
DockerContext: .
Dockerfile: Dockerfile
Properties:
PackageType: Image
FileSystemConfigs:
- Arn: !GetAtt AccessPoint.Arn
LocalMountPath: /mnt/shop
Events:
ApiEvent:
Type: Api
Properties:
Path: /path
Method: get
```
Contributor guide
Assessment
This issue has not been assessed yet.