Describe your idea/feature/enhancement
For Python applications, it'd be ideal to have a flag in sam build to preserve the parent folder in CodeUri when building and copying artifacts to $ARTIFACTS_DIR.
For example, I wish SAM CLI could allow Python developers to keep their layout for modules like we do elsewhere:
Ideal
.
├── loyalty
│ └── __init__.py
│ └── aggregate
│ ├── __init__.py
│ └── app.py
│ └── get
│ ├── __init__.py
│ └── app.py
│ └── ingest
│ ├── __init__.py
│ └── app.py
│ └── shared
│ ├── __init__.py
│ ├── constants.py
│ ├── functions.py
│ ├── models.py
│ └── storage.py
├── template.yaml
└── tests
├── conftest.py
├── events
│ ├── aggregate_insert_event.json
│ ├── get_event.json
│ └── ingest_event.json
├── storage
│ ├── __init__.py
│ └── test_dynamodb.py
└── unit
├── __init__.py
├── test_aggregate.py
├── test_get_loyalty_points.py
└── test_ingest.py
Template
...
IngestFunc:
Type: AWS::Serverless::Function
Properties:
FunctionName: !Sub ServerlessAirline-IngestLoyalty-${Stage}
CodeUri: loyalty
Handler: loyalty.ingest.app.lambda_handler
Import line as well as tests
from loyalty.shared.models import LoyaltyPoint, LoyaltyPointAggregate
from loyalty.shared.storage import FakeStorage, DynamoDBStorage
...
To workaround this issue, I have to create another folder src to get the intended result[1], but this creates other problems in PYTHONPATH which I need to adjust in my IDE and tools later. Alternatively, I could use BuildMethod: makefile in SAM, but then I to lose dedup functionality.
Steps to reproduce the issue:
- Use
loyalty as CodeUri
- Run
sam build
Observed result: loyalty parent folder will not be copied over but its contents
Expected result: A flag to ensure folder in CodeUri is preserved when building artifacts, e.g. --preserve-, or perhaps respect foldervsfolder/`.
Additional environment details (Ex: Windows, Mac, Amazon Linux etc) Mac
Implementation in question that deliberately removes the parent folder: https://github.com/aws/aws-lambda-builders/blob/41804217a18ff47cce5b62eff5cf884a7f81a0c5/aws_lambda_builders/utils.py#L16
Lambda Builders related issue: aws/aws-lambda-builders#283
[1] Current layout to ensure loyalty folder is copied over (CodeUri: src):
.
├── src
│ └── loyalty
│ ├── __init__.py
│ ├── aggregate
│ │ ├── __init__.py
│ │ └── app.py
│ ├── get
│ │ ├── __init__.py
│ │ └── app.py
│ ├── ingest
│ │ ├── __init__.py
│ │ └── app.py
│ └── shared
│ ├── __init__.py
│ ├── constants.py
│ ├── functions.py
│ ├── models.py
│ └── storage.py
├── template.yaml
└── tests
├── conftest.py
├── events
│ ├── aggregate_insert_event.json
│ ├── get_event.json
│ └── ingest_event.json
├── storage
│ ├── __init__.py
│ └── test_dynamodb.py
└── unit
├── __init__.py
├── test_aggregate.py
├── test_get_loyalty_points.py
└── test_ingest.py
Proposal
A new CLI flag --preserve-code-uri, --preserve, etc.
Things to consider:
- Will this require any updates to the SAM Spec
Additional Details
Describe your idea/feature/enhancement
For Python applications, it'd be ideal to have a flag in
sam buildto preserve the parent folder in CodeUri when building and copying artifacts to $ARTIFACTS_DIR.For example, I wish SAM CLI could allow Python developers to keep their layout for modules like we do elsewhere:
Ideal
. ├── loyalty │ └── __init__.py │ └── aggregate │ ├── __init__.py │ └── app.py │ └── get │ ├── __init__.py │ └── app.py │ └── ingest │ ├── __init__.py │ └── app.py │ └── shared │ ├── __init__.py │ ├── constants.py │ ├── functions.py │ ├── models.py │ └── storage.py ├── template.yaml └── tests ├── conftest.py ├── events │ ├── aggregate_insert_event.json │ ├── get_event.json │ └── ingest_event.json ├── storage │ ├── __init__.py │ └── test_dynamodb.py └── unit ├── __init__.py ├── test_aggregate.py ├── test_get_loyalty_points.py └── test_ingest.pyTemplate
Import line as well as tests
To workaround this issue, I have to create another folder
srcto get the intended result[1], but this creates other problems in PYTHONPATH which I need to adjust in my IDE and tools later. Alternatively, I could useBuildMethod: makefilein SAM, but then I to losededupfunctionality.Steps to reproduce the issue:
loyaltyasCodeUrisam buildObserved result:
loyaltyparent folder will not be copied over but its contentsExpected result: A flag to ensure folder in
CodeUriis preserved when building artifacts, e.g.--preserve-, or perhaps respectfoldervsfolder/`.Additional environment details (Ex: Windows, Mac, Amazon Linux etc) Mac
Implementation in question that deliberately removes the parent folder: https://github.com/aws/aws-lambda-builders/blob/41804217a18ff47cce5b62eff5cf884a7f81a0c5/aws_lambda_builders/utils.py#L16
Lambda Builders related issue: aws/aws-lambda-builders#283
[1] Current layout to ensure loyalty folder is copied over (
CodeUri: src):. ├── src │ └── loyalty │ ├── __init__.py │ ├── aggregate │ │ ├── __init__.py │ │ └── app.py │ ├── get │ │ ├── __init__.py │ │ └── app.py │ ├── ingest │ │ ├── __init__.py │ │ └── app.py │ └── shared │ ├── __init__.py │ ├── constants.py │ ├── functions.py │ ├── models.py │ └── storage.py ├── template.yaml └── tests ├── conftest.py ├── events │ ├── aggregate_insert_event.json │ ├── get_event.json │ └── ingest_event.json ├── storage │ ├── __init__.py │ └── test_dynamodb.py └── unit ├── __init__.py ├── test_aggregate.py ├── test_get_loyalty_points.py └── test_ingest.pyProposal
A new CLI flag
--preserve-code-uri,--preserve, etc.Things to consider:
Additional Details