Skip to content

Commit 4ed914d

Browse files
Merge pull request #58 from developmentseed/fix/environment-vars
Fix/environment vars
2 parents 7dbff51 + e501bc0 commit 4ed914d

File tree

7 files changed

+51
-26
lines changed

7 files changed

+51
-26
lines changed

.github/actions/cdk-deploy/action.yml

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -88,5 +88,3 @@ runs:
8888
working-directory: ${{ inputs.dir }}
8989
run: uv run cdk deploy --all --require-approval never --outputs-file ${HOME}/cdk-outputs.json
9090
shell: bash
91-
env:
92-
TITILER_CMR_ADDITIONAL_ENV: '{"TITILER_CMR_S3_AUTH_STRATEGY":"iam"}'
Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -52,7 +52,9 @@ jobs:
5252
dir: "./infrastructure/aws"
5353
env_aws_secret_name: ""
5454
env:
55+
# I'm not sure this is in use anymore, should we remove it?
5556
TITILER_CMR_ROLE_ARN: ${{ secrets.titiler_cmr_role_arn }}
5657
TITILER_CMR_ROOT_PATH: ''
5758
STAGE: dev
58-
ADDITIONAL_ENV: '{"AWS_REQUEST_PAYER": "requester"}'
59+
TITILER_CMR_AWS_REQUEST_PAYER: requester
60+
TITILER_CMR_S3_AUTH_STRATEGY: iam

CHANGELOG.md

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,14 @@ The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.0.0/).
66

77
## [Unreleased]
88

9+
### Added
10+
11+
### Fixed
12+
13+
### Changed
14+
15+
- Add `s3_auth_strategy` and `aws_request_payer` to `AppSettings`: https://github.com/developmentseed/titiler-cmr/pull/58
16+
917
## [v0.1.4]
1018

1119
### Added

README.md

Lines changed: 11 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -95,10 +95,20 @@ TITILER_CMR_S3_AUTH_ACCESS=external uvicorn titiler.cmr.main:app --reload
9595

9696
The application will be available at this address: [http://localhost:8000/api.html](http://localhost:8000/api.html)
9797

98-
## Deployment to AWS
98+
## Deployment to AWS via `veda-deploy`
9999

100100
Deployment to AWS is currently triggered using [veda-deploy](https://github.com/NASA-IMPACT/veda-deploy). veda-deploy checks out this repo as a submodule and then executes [.github/actions/cdk-deploy/action.yml](.github/actions/cdk-deploy/action.yml) (see also: [veda-deploy/.github/workflows/deploy.yml](https://github.com/NASA-IMPACT/veda-deploy/blob/dev/.github/workflows/deploy.yml)). For more details, please review the [veda-deploy README section on adding new components](https://github.com/NASA-IMPACT/veda-deploy/tree/dev?tab=readme-ov-file#add-new-components).
101101

102+
### Environment Variables
103+
104+
Environment variables for the `veda-deploy` deployment should be configured in the `veda-deploy` environment-specific AWS Secret. See also [these instructions](https://github.com/NASA-IMPACT/veda-deploy/tree/dev?tab=readme-ov-file#store-env-configuration-in-aws-secrets-manager). The variables in the AWS Secret will be written to an `.env` file and used by the CDK deployment as instantiated by the `AppSettings` and `StackSettings` defined [infrastructure/aws/cdk/config.py](infrastructure/aws/cdk/config.py). `StackSettings` are those specific to the specific stage being deployed, may only be used during deployment, and are more likely to be shared across VEDA services. `AppSettings` are settings specific to titiler-cmr and are used to set the lambda runtime environment variables.
105+
106+
The application-specific (`AppSettings`) environment variables which should be set in the `veda-deploy` AWS secret are:
107+
108+
* `TITILER_CMR_S3_AUTH_STRATEGY=iam`
109+
* `TITILER_CMR_ROOT_PATH=/api/titiler-cmr`
110+
* `TITILER_CMR_AWS_REQUEST_PAYER=requester`
111+
102112
### Deployment to a development/test instance
103113

104114
You can trigger a deploy to a "dev" stack (cloudformation stack name should be `titiler-cmr-dev`) in the VEDA SMCE account by labeling a PR with the "deploy-dev" tag. This stack is intended for testing new features.

infrastructure/aws/cdk/app.py

Lines changed: 11 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
"""Construct App."""
22

33
import os
4-
from typing import Any, Dict, List, Optional
4+
from typing import Any, List, Optional
55

66
from aws_cdk import App, CfnOutput, Duration, Stack, Tags, aws_lambda
77
from aws_cdk import aws_apigatewayv2 as apigw
@@ -42,7 +42,6 @@ def __init__(
4242
runtime: aws_lambda.Runtime = aws_lambda.Runtime.PYTHON_3_10,
4343
concurrent: Optional[int] = None,
4444
permissions: Optional[List[iam.PolicyStatement]] = None,
45-
environment: Optional[Dict] = None,
4645
role_arn: Optional[str] = None,
4746
context_dir: str = "../../",
4847
**kwargs: Any,
@@ -51,7 +50,6 @@ def __init__(
5150
super().__init__(scope, id, *kwargs)
5251

5352
permissions = permissions or []
54-
environment = environment or {}
5553

5654
iam_reader_role = None
5755
if role_arn:
@@ -61,6 +59,15 @@ def __init__(
6159
role_arn=role_arn,
6260
)
6361

62+
lambda_env = {
63+
**DEFAULT_ENV,
64+
"TITILER_CMR_ROOT_PATH": app_settings.root_path,
65+
"TITILER_CMR_S3_AUTH_STRATEGY": app_settings.s3_auth_strategy,
66+
}
67+
68+
if app_settings.aws_request_payer:
69+
lambda_env["AWS_REQUEST_PAYER"] = app_settings.aws_request_payer
70+
6471
lambda_function = aws_lambda.Function(
6572
self,
6673
f"{id}-lambda",
@@ -74,11 +81,7 @@ def __init__(
7481
memory_size=memory,
7582
reserved_concurrent_executions=concurrent,
7683
timeout=Duration.seconds(timeout),
77-
environment={
78-
**DEFAULT_ENV,
79-
**environment,
80-
"TITILER_CMR_ROOT_PATH": app_settings.root_path,
81-
},
84+
environment=lambda_env,
8285
log_retention=logs.RetentionDays.ONE_WEEK,
8386
role=iam_reader_role,
8487
)
@@ -154,7 +157,6 @@ def __init__(
154157
concurrent=app_settings.max_concurrent,
155158
role_arn=app_settings.role_arn,
156159
permissions=perms,
157-
environment=stack_settings.additional_env,
158160
)
159161
# Tag infrastructure
160162
for key, value in {

infrastructure/aws/cdk/config.py

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
"""STACK Configs."""
22

3-
from typing import Dict, List, Optional
3+
from typing import List, Optional
44

55
from pydantic_settings import BaseSettings, SettingsConfigDict
66

@@ -10,7 +10,6 @@ class StackSettings(BaseSettings):
1010

1111
veda_custom_host: Optional[str] = None
1212
stage: str = "production"
13-
additional_env: Dict = {}
1413

1514
model_config = SettingsConfigDict(env_file=".env", extra="ignore")
1615

@@ -43,6 +42,8 @@ class AppSettings(BaseSettings):
4342
max_concurrent: Optional[int] = None
4443
alarm_email: Optional[str] = None
4544
root_path: Optional[str] = None
45+
s3_auth_strategy: Optional[str] = "environment"
46+
aws_request_payer: Optional[str] = None
4647

4748
model_config = SettingsConfigDict(
4849
env_prefix="TITILER_CMR_", env_file=".env", extra="ignore"

uv.lock

Lines changed: 15 additions & 11 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

0 commit comments

Comments
 (0)