diff --git a/.github/workflows/build.yaml b/.github/workflows/build.yaml index fee9392..4a206d1 100644 --- a/.github/workflows/build.yaml +++ b/.github/workflows/build.yaml @@ -12,7 +12,7 @@ on: required: false DS_RELEASE_BOT_PRIVATE_KEY: required: false - + jobs: build_and_package: name: Build and package @@ -22,7 +22,7 @@ jobs: - uses: actions/setup-node@v3 with: - node-version: 16 + node-version: 18 cache: "npm" - name: Install Dependencies @@ -66,7 +66,7 @@ jobs: private_key: ${{ secrets.DS_RELEASE_BOT_PRIVATE_KEY }} - name: Maybe Release 🚀 - if: ${{ inputs.release }} + if: "${{ inputs.release }}" run: | npm run semantic-release env: diff --git a/.github/workflows/test.yaml b/.github/workflows/build_and_release.yaml similarity index 89% rename from .github/workflows/test.yaml rename to .github/workflows/build_and_release.yaml index e543929..83219c0 100644 --- a/.github/workflows/test.yaml +++ b/.github/workflows/build_and_release.yaml @@ -1,4 +1,4 @@ -name: Test & Build +name: Build & try to release on: push: diff --git a/.github/workflows/deploy.yaml b/.github/workflows/deploy.yaml new file mode 100644 index 0000000..82245aa --- /dev/null +++ b/.github/workflows/deploy.yaml @@ -0,0 +1,76 @@ +name: Test deployment + +on: + merge_group: + branches: [ main ] + +jobs: + build_package_and_deploy: + name: Build, package and deploy + runs-on: ubuntu-latest + timeout-minutes: 60 + env: + AWS_DEFAULT_REGION: ${{ secrets.AWS_DEFAULT_REGION_DEPLOY }} + AWS_ACCESS_KEY_ID: ${{ secrets.AWS_ACCESS_KEY_ID_DEPLOY }} + AWS_SECRET_ACCESS_KEY: ${{ secrets.AWS_SECRET_ACCESS_KEY_DEPLOY }} + AWS_DEFAULT_ACCOUNT: ${{ secrets.AWS_ACCOUNT_ID }} + steps: + - uses: actions/checkout@v3 + + - uses: actions/setup-node@v3 + with: + node-version: 18 + cache: "npm" + + - name: Install Dependencies + run: npm ci + + - name: Compile project + run: npm run build + + - name: Generate distribution packages + run: npm run package + + + - name: Install deployment environment + id: install_deploy_env + run: | + # install deployment environment with eoapi-cdk from build + python -m venv .deployment_venv + source .deployment_venv/bin/activate + pip install dist/python/*.gz + cd integration_tests/cdk + pip install -r requirements.txt + npm install + deactivate + cd - + + + - name: Deploy test stack + id: deploy_step + run: | + source .deployment_venv/bin/activate + + # synthesize the stack + cd integration_tests/cdk + npx cdk synth --debug --all --require-approval never + + # deploy the stack + npx cdk deploy --ci --all --require-approval never + deactivate + cd - + + - name: Tear down any infrastructure + if: always() + run: | + cd integration_tests/cdk + # run this only if we find a 'cdk.out' directory, which means there might be things to tear down + if [ -d "cdk.out" ]; then + cd - + source .deployment_venv/bin/activate + cd integration_tests/cdk + # see https://github.com/aws/aws-cdk/issues/24946 + # this didn't work : rm -f cdk.out/synth.lock + # so we just duplicate the cdk output to cdk-destroy.out + npx cdk destroy --output cdk-destroy.out --ci --all --force + fi diff --git a/.github/workflows/distribute.yaml b/.github/workflows/distribute.yaml index e4600a3..960d4a4 100644 --- a/.github/workflows/distribute.yaml +++ b/.github/workflows/distribute.yaml @@ -13,11 +13,12 @@ jobs: runs-on: ubuntu-latest needs: package steps: + - uses: actions/download-artifact@v3 with: name: python path: dist - + - run: pip install twine - run: twine upload dist/* diff --git a/.gitignore b/.gitignore index da73da4..0ce8378 100644 --- a/.gitignore +++ b/.gitignore @@ -8,3 +8,6 @@ docs __pycache__ .venv .tox +tests/*.egg* +tests/*venv* +tests/__pycache__ \ No newline at end of file diff --git a/README.md b/README.md index 62ad4ad..698f7a2 100644 --- a/README.md +++ b/README.md @@ -54,3 +54,6 @@ Versioning is automatically handled via [Conventional Commits](https://www.conve _Warning_: If you rebase `main`, you must ensure that the commits referenced by tags point to commits that are within the `main` branch. If a commit references a commit that is no longer on the `main` branch, Semantic Release will fail to detect the correct version of the project. [More information](https://github.com/semantic-release/semantic-release/issues/1121#issuecomment-517945233). +## Tests + +Each pull request to `main` is added to a [merge queue](https://docs.github.com/en/repositories/configuring-branches-and-merges-in-your-repository/configuring-pull-request-merges/managing-a-merge-queue#triggering-merge-group-checks-with-github-actions) so that a "deployment test" workflow can run before the merge actually happens. If the deployment fails, the merge is cancelled. Here is [the definition of this workflow](https://github.com/developmentseed/eoapi-cdk/blob/main/.github/workflows/deploy.yaml) and the [tests definition](https://github.com/developmentseed/eoapi-cdk/blob/main/tests). \ No newline at end of file diff --git a/integration_tests/cdk/README.md b/integration_tests/cdk/README.md new file mode 100644 index 0000000..18232d4 --- /dev/null +++ b/integration_tests/cdk/README.md @@ -0,0 +1,55 @@ + +# Deployment CDK code for eoapi-cdk deployment tests + +This is a wrapper CDK code that is used to test a deployment of the `eoapi-cdk` constructs before a release happens. + +## Requirements + +- python +- docker +- node +- AWS credentials environment variables configured to point to an account. + +## Installation + +Install python dependencies with + +``` +python -m venv .venv +source .venv/bin/activate +python -m pip install -r requirements.txt +``` + +Install the latest `eoapi-cdk` either from PyPI: + +``` +pip install eoapi-cdk +``` + +Or alternatively, compile and package from the root of this repository to get the python version of the constructs locally. + +Also install node dependencies with + +``` +npm install +``` + +Verify that the `cdk` CLI is available. Since `aws-cdk` is installed as a local dependency, you can use the `npx` node package runner tool, that comes with `npm`. + +``` +npx cdk --version +``` + +## Deployment + +First, synthesize the app + +``` +npx cdk synth --all +``` + +Then, deploy + +``` +npx cdk deploy --all --require-approval never +``` \ No newline at end of file diff --git a/integration_tests/cdk/app.py b/integration_tests/cdk/app.py new file mode 100644 index 0000000..f86c201 --- /dev/null +++ b/integration_tests/cdk/app.py @@ -0,0 +1,17 @@ +from aws_cdk import App + +from config import build_app_config +from eoapi_template import pgStacInfra, vpc + +app = App() + +app_config = build_app_config() + +vpc_stack = vpc.VpcStack(scope=app, app_config=app_config) + +pgstac_infra_stack = pgStacInfra.pgStacInfraStack( + scope=app, + vpc=vpc_stack.vpc, + app_config=app_config, +) +app.synth() diff --git a/integration_tests/cdk/cdk.json b/integration_tests/cdk/cdk.json new file mode 100644 index 0000000..d9313bf --- /dev/null +++ b/integration_tests/cdk/cdk.json @@ -0,0 +1,32 @@ +{ + "app": "python3 app.py", + "watch": { + "include": [ + "**" + ], + "exclude": [ + "README.md", + "cdk*.json", + "requirements*.txt", + "source.bat", + "**/*.pyc", + "**/*.tmp", + "**/__pycache__", + "tests", + "scripts", + "*venv" + ] + }, + "context": { + "@aws-cdk/aws-apigateway:usagePlanKeyOrderInsensitiveId": true, + "@aws-cdk/core:stackRelativeExports": true, + "@aws-cdk/aws-rds:lowercaseDbIdentifier": true, + "@aws-cdk/aws-lambda:recognizeVersionProps": true, + "@aws-cdk/aws-cloudfront:defaultSecurityPolicyTLSv1.2_2021": true, + "@aws-cdk-containers/ecs-service-extensions:enableDefaultLogDriver": true, + "@aws-cdk/core:target-partitions": [ + "aws", + "aws-cn" + ] + } +} \ No newline at end of file diff --git a/integration_tests/cdk/config.py b/integration_tests/cdk/config.py new file mode 100644 index 0000000..729aa8c --- /dev/null +++ b/integration_tests/cdk/config.py @@ -0,0 +1,58 @@ +from typing import Dict + +import pydantic +import yaml +from pydantic_core.core_schema import FieldValidationInfo +from pydantic_settings import BaseSettings, SettingsConfigDict + + +class AppConfig(BaseSettings): + model_config = SettingsConfigDict( + env_file=".env" + ) + aws_default_account: str = pydantic.Field( + description="AWS account ID" + ) + project_id: str = pydantic.Field( + description="Project ID", default="eoapi-cdk" + ) + stage: str = pydantic.Field(description="Stage of deployment", default="test") + # because of its validator, `tags` should always come after `project_id` and `stage` + tags: Dict[str, str] | None = pydantic.Field( + description="""Tags to apply to resources. If none provided, + will default to the defaults defined in `default_tags`. + Note that if tags are passed to the CDK CLI via `--tags`, + they will override any tags defined here.""", + default=None, + ) + db_instance_type: str = pydantic.Field( + description="Database instance type", default="t3.micro" + ) + db_allocated_storage: int = pydantic.Field( + description="Allocated storage for the database", default=5 + ) + + @pydantic.field_validator("tags") + def default_tags(cls, v, info: FieldValidationInfo): + return v or {"project_id": info.data["project_id"], "stage": info.data["stage"]} + + def build_service_name(self, service_id: str) -> str: + return f"{self.project_id}-{self.stage}-{service_id}" + + +def build_app_config() -> AppConfig: + """Builds the AppConfig object from config.yaml file if exists, + otherwise use defaults""" + try: + with open("config.yaml") as f: + print("Loading config from config.yaml") + app_config = yaml.safe_load(f) + app_config = ( + {} if app_config is None else app_config + ) # if config is empty, set it to an empty dict + app_config = AppConfig(**app_config) + except FileNotFoundError: + # if no config at the expected path, using defaults + app_config = AppConfig() + + return app_config diff --git a/integration_tests/cdk/eoapi_template/__init__.py b/integration_tests/cdk/eoapi_template/__init__.py new file mode 100644 index 0000000..e69de29 diff --git a/integration_tests/cdk/eoapi_template/pgStacInfra.py b/integration_tests/cdk/eoapi_template/pgStacInfra.py new file mode 100644 index 0000000..cbb5491 --- /dev/null +++ b/integration_tests/cdk/eoapi_template/pgStacInfra.py @@ -0,0 +1,71 @@ +from aws_cdk import ( + Stack, + aws_ec2, + aws_rds +) +from constructs import Construct +from eoapi_cdk import ( + PgStacApiLambda, + PgStacDatabase, + TitilerPgstacApiLambda, +) + +from config import AppConfig + + +class pgStacInfraStack(Stack): + def __init__( + self, + scope: Construct, + vpc: aws_ec2.Vpc, + app_config: AppConfig, + **kwargs, + ) -> None: + super().__init__( + scope, + id=app_config.build_service_name("pgSTAC-infra"), + tags=app_config.tags, + **kwargs, + ) + + pgstac_db = PgStacDatabase( + self, + "pgstac-db", + vpc=vpc, + engine=aws_rds.DatabaseInstanceEngine.postgres( + version=aws_rds.PostgresEngineVersion.VER_14 + ), + vpc_subnets=aws_ec2.SubnetSelection( + subnet_type=aws_ec2.SubnetType.PUBLIC, + ), + allocated_storage=app_config.db_allocated_storage, + instance_type=aws_ec2.InstanceType(app_config.db_instance_type) + ) + + pgstac_db.db.connections.allow_default_port_from_any_ipv4() + + PgStacApiLambda( + self, + "pgstac-api", + api_env={ + "NAME": app_config.build_service_name("STAC API"), + "description": f"{app_config.stage} STAC API", + }, + db=pgstac_db.db, + db_secret=pgstac_db.pgstac_secret + ) + + TitilerPgstacApiLambda( + self, + "titiler-pgstac-api", + api_env={ + "NAME": app_config.build_service_name("titiler pgSTAC API"), + "description": f"{app_config.stage} titiler pgstac API", + }, + db=pgstac_db.db, + db_secret=pgstac_db.pgstac_secret, + buckets=[], + lambda_function_options={ + "allow_public_subnet": True, + }, + ) diff --git a/integration_tests/cdk/eoapi_template/vpc.py b/integration_tests/cdk/eoapi_template/vpc.py new file mode 100644 index 0000000..d17967f --- /dev/null +++ b/integration_tests/cdk/eoapi_template/vpc.py @@ -0,0 +1,49 @@ +from aws_cdk import Stack, aws_ec2 +from constructs import Construct + +from config import AppConfig + + +class VpcStack(Stack): + def __init__(self, scope: Construct, app_config: AppConfig, **kwargs) -> None: + super().__init__( + scope, + id=app_config.build_service_name("pgSTAC-vpc"), + tags=app_config.tags, + **kwargs + ) + + self.vpc = aws_ec2.Vpc( + self, + "vpc", + subnet_configuration=[ + aws_ec2.SubnetConfiguration( + name="ingress", subnet_type=aws_ec2.SubnetType.PUBLIC, cidr_mask=24 + ), + ] + ) + + self.vpc.add_interface_endpoint( + "SecretsManagerEndpoint", + service=aws_ec2.InterfaceVpcEndpointAwsService.SECRETS_MANAGER, + ) + + self.vpc.add_interface_endpoint( + "CloudWatchEndpoint", + service=aws_ec2.InterfaceVpcEndpointAwsService.CLOUDWATCH_LOGS, + ) + + self.vpc.add_gateway_endpoint( + "S3", service=aws_ec2.GatewayVpcEndpointAwsService.S3 + ) + + self.export_value( + self.vpc.select_subnets(subnet_type=aws_ec2.SubnetType.PUBLIC) + .subnets[0] + .subnet_id + ) + self.export_value( + self.vpc.select_subnets(subnet_type=aws_ec2.SubnetType.PUBLIC) + .subnets[1] + .subnet_id + ) diff --git a/integration_tests/cdk/package-lock.json b/integration_tests/cdk/package-lock.json new file mode 100644 index 0000000..5fa908a --- /dev/null +++ b/integration_tests/cdk/package-lock.json @@ -0,0 +1,42 @@ +{ + "name": "eoapi-template", + "version": "0.1.0", + "lockfileVersion": 3, + "requires": true, + "packages": { + "": { + "name": "eoapi-template", + "version": "0.1.0", + "dependencies": { + "aws-cdk": "^2.99.1" + } + }, + "node_modules/aws-cdk": { + "version": "2.128.0", + "resolved": "https://registry.npmjs.org/aws-cdk/-/aws-cdk-2.128.0.tgz", + "integrity": "sha512-epOAr/0WKqmyaKqBc7N0Ky5++93pu+v6yVN9jNOa4JYkAkGbeTS3vR9bj/W0o94jnlgWevG3HNHr83jtRvw/4A==", + "bin": { + "cdk": "bin/cdk" + }, + "engines": { + "node": ">= 14.15.0" + }, + "optionalDependencies": { + "fsevents": "2.3.2" + } + }, + "node_modules/fsevents": { + "version": "2.3.2", + "resolved": "https://registry.npmjs.org/fsevents/-/fsevents-2.3.2.tgz", + "integrity": "sha512-xiqMQR4xAeHTuB9uWm+fFRcIOgKBMiOBP+eXiyT7jsgVCq1bkVygt00oASowB7EdtpOHaaPgKt812P9ab+DDKA==", + "hasInstallScript": true, + "optional": true, + "os": [ + "darwin" + ], + "engines": { + "node": "^8.16.0 || ^10.6.0 || >=11.0.0" + } + } + } +} diff --git a/integration_tests/cdk/package.json b/integration_tests/cdk/package.json new file mode 100644 index 0000000..aaaa2d9 --- /dev/null +++ b/integration_tests/cdk/package.json @@ -0,0 +1,8 @@ +{ + "name": "eoapi-template", + "version": "0.1.0", + "dependencies": { + "aws-cdk": "^2.99.1" + } + } + \ No newline at end of file diff --git a/integration_tests/cdk/requirements.txt b/integration_tests/cdk/requirements.txt new file mode 100644 index 0000000..540a518 --- /dev/null +++ b/integration_tests/cdk/requirements.txt @@ -0,0 +1,7 @@ +aws-cdk-lib>=2.99.1 +constructs>=10.0.0,<11.0.0 +pydantic==2.0.2 +pydantic-settings==2.0.1 +python-dotenv==1.0.0 +pyyaml==6.0 +types-PyYAML==6.0.12.10 diff --git a/lib/database/bootstrapper_runtime/handler.py b/lib/database/bootstrapper_runtime/handler.py index 0334729..317e5a0 100644 --- a/lib/database/bootstrapper_runtime/handler.py +++ b/lib/database/bootstrapper_runtime/handler.py @@ -2,6 +2,7 @@ Custom resource lambda handler to bootstrap Postgres db. Source: https://github.com/developmentseed/eoAPI/blob/master/deployment/handlers/db_handler.py """ + import json import boto3 @@ -58,7 +59,12 @@ def send( headers = {"content-type": "", "content-length": str(len(json_responseBody))} try: - response = httpx.put(responseUrl, data=json_responseBody, headers=headers) + response = httpx.put( + responseUrl, + data=json_responseBody, + headers=headers, + timeout=30, + ) print("Status code: " + response.status_code) except Exception as e: print("send(..) failed executing httpx.put(..): " + str(e)) diff --git a/lib/database/index.ts b/lib/database/index.ts index 481f322..2e64efe 100644 --- a/lib/database/index.ts +++ b/lib/database/index.ts @@ -60,7 +60,7 @@ export class PgStacDatabase extends Construct { }); const handler = new aws_lambda.Function(this, "lambda", { - // defaults for configurable properties + // defaults runtime: aws_lambda.Runtime.PYTHON_3_11, handler: "handler.handler", memorySize: 128, @@ -70,11 +70,10 @@ export class PgStacDatabase extends Construct { file: "bootstrapper_runtime/Dockerfile", buildArgs: {PGSTAC_VERSION: DEFAULT_PGSTAC_VERSION, PYTHON_VERSION: "3.11"} }), - // overwrites defaults with user-provided configurable properties - ...props.bootstrapperLambdaFunctionOptions, - // Non configurable properties that are going to be overwritten even if provided by the user vpc: hasVpc(this.db) ? this.db.vpc : props.vpc, - allowPublicSubnet: true + allowPublicSubnet: true, + // overwrites defaults with user-provided configurable properties, + ...props.bootstrapperLambdaFunctionOptions, }); this.pgstacSecret = new secretsmanager.Secret(this, "bootstrappersecret", { @@ -204,7 +203,7 @@ export interface PgStacDatabaseProps extends rds.DatabaseInstanceProps { } /** - * Optional settings for the bootstrapper lambda function. Can be anything that can be configured on the lambda function, but some will be overwritten by values defined here. + * Can be used to override the default lambda function properties. * * @default - defined in the construct. */ diff --git a/lib/ingestor-api/index.ts b/lib/ingestor-api/index.ts index c36baad..e39f7ce 100644 --- a/lib/ingestor-api/index.ts +++ b/lib/ingestor-api/index.ts @@ -115,7 +115,7 @@ export class StacIngestor extends Construct { }): lambda.Function { const handler = new lambda.Function(this, "api-handler", { - // defaults for configurable properties + // defaults runtime: lambda.Runtime.PYTHON_3_11, handler: "src.handler.handler", memorySize: 2048, @@ -125,14 +125,13 @@ export class StacIngestor extends Construct { file: "runtime/Dockerfile", buildArgs: { PYTHON_VERSION: '3.11' }, }), - // overwrites defaults with user-provided configurable properties - ...props.lambdaFunctionOptions, - // Non configurable properties that are going to be overwritten even if provided by the user + allowPublicSubnet: true, vpc: props.dbVpc, vpcSubnets: props.subnetSelection, - allowPublicSubnet: true, environment: { DB_SECRET_ARN: props.dbSecret.secretArn, ...props.env }, - role: this.handlerRole + role: this.handlerRole, + // overwrites defaults with user-provided configurable properties + ...props.lambdaFunctionOptions, }); // Allow handler to read DB secret @@ -165,7 +164,7 @@ export class StacIngestor extends Construct { const handler = new lambda.Function(this, "stac-ingestor",{ - // defaults for configurable properties + // defaults runtime: lambda.Runtime.PYTHON_3_11, handler: "src.ingestor.handler", memorySize: 2048, @@ -175,15 +174,13 @@ export class StacIngestor extends Construct { file: "runtime/Dockerfile", buildArgs: { PYTHON_VERSION: '3.11' }, }), - // overwrites defaults with user-provided configurable properties - ...props.lambdaFunctionOptions, - - // Non configurable properties that are going to be overwritten even if provided by the user vpc: props.dbVpc, vpcSubnets: props.subnetSelection, allowPublicSubnet: true, environment: { DB_SECRET_ARN: props.dbSecret.secretArn, ...props.env }, - role: this.handlerRole + role: this.handlerRole, + // overwrites defaults with user-provided configurable properties + ...props.lambdaFunctionOptions, }); // Allow handler to read DB secret @@ -322,14 +319,14 @@ export interface StacIngestorProps { readonly ingestorDomainNameOptions?: apigateway.DomainNameOptions; /** - * Optional settings for the lambda function. Can be anything that can be configured on the lambda function, but some will be overwritten by values defined here. + * Can be used to override the default lambda function properties. * * @default - default settings are defined in the construct. */ readonly apiLambdaFunctionOptions?: CustomLambdaFunctionProps; /** - * Optional settings for the lambda function. Can be anything that can be configured on the lambda function, but some will be overwritten by values defined here. + * Can be used to override the default lambda function properties. * * @default - default settings are defined in the construct. */ diff --git a/lib/ingestor-api/runtime/dev_requirements.txt b/lib/ingestor-api/runtime/dev_requirements.txt index 4270b89..81c05ba 100644 --- a/lib/ingestor-api/runtime/dev_requirements.txt +++ b/lib/ingestor-api/runtime/dev_requirements.txt @@ -1,2 +1,2 @@ httpx -moto[dynamodb, ssm]>=4.0.9 \ No newline at end of file +moto[dynamodb, ssm]>=4.0.9,<5.0 diff --git a/lib/ingestor-api/runtime/src/loader.py b/lib/ingestor-api/runtime/src/loader.py index 82fa7f9..5cbd486 100644 --- a/lib/ingestor-api/runtime/src/loader.py +++ b/lib/ingestor-api/runtime/src/loader.py @@ -1,4 +1,5 @@ """Utilities to bulk load data into pgstac from json/ndjson.""" + import logging from pypgstac.load import Loader as BaseLoader diff --git a/lib/ingestor-api/runtime/src/services.py b/lib/ingestor-api/runtime/src/services.py index ee827a5..ef263fe 100644 --- a/lib/ingestor-api/runtime/src/services.py +++ b/lib/ingestor-api/runtime/src/services.py @@ -40,5 +40,5 @@ def fetch_many( } -class NotInDb(Exception): +class NotInDb(Exception): # noqa ... diff --git a/lib/stac-api/index.ts b/lib/stac-api/index.ts index bcfe434..77c4bc2 100644 --- a/lib/stac-api/index.ts +++ b/lib/stac-api/index.ts @@ -23,7 +23,7 @@ export class PgStacApiLambda extends Construct { console.log(props) console.log(props.lambdaFunctionOptions); this.stacApiLambdaFunction = new lambda.Function(this, "lambda", { - // defaults for configurable properties + // defaults runtime: lambda.Runtime.PYTHON_3_11, handler: "src.handler.handler", memorySize: 8192, @@ -33,9 +33,6 @@ export class PgStacApiLambda extends Construct { file: "runtime/Dockerfile", buildArgs: { PYTHON_VERSION: '3.11' }, }), - // overwrites defaults with user-provided configurable properties - ...props.lambdaFunctionOptions, - // Non configurable properties that are going to be overwritten even if provided by the user vpc: props.vpc, vpcSubnets: props.subnetSelection, allowPublicSubnet: true, @@ -45,6 +42,8 @@ export class PgStacApiLambda extends Construct { DB_MAX_CONN_SIZE: "1", ...props.apiEnv, }, + // overwrites defaults with user-provided configurable properties + ...props.lambdaFunctionOptions }); props.dbSecret.grantRead(this.stacApiLambdaFunction); @@ -99,7 +98,7 @@ export interface PgStacApiLambdaProps { readonly stacApiDomainName?: IDomainName; /** - * Optional settings for the lambda function. Can be anything that can be configured on the lambda function, but some will be overwritten by values defined here. + * Can be used to override the default lambda function properties. * * @default - defined in the construct. */ diff --git a/lib/stac-api/runtime/src/config.py b/lib/stac-api/runtime/src/config.py index 27dfe6d..948dc8a 100644 --- a/lib/stac-api/runtime/src/config.py +++ b/lib/stac-api/runtime/src/config.py @@ -1,5 +1,6 @@ """API settings. Based on https://github.com/developmentseed/eoAPI/tree/master/src/eoapi/stac""" + import base64 import json from typing import Optional diff --git a/lib/tipg-api/index.ts b/lib/tipg-api/index.ts index d50518b..d40a3df 100644 --- a/lib/tipg-api/index.ts +++ b/lib/tipg-api/index.ts @@ -21,7 +21,7 @@ import { super(scope, id); this.tiPgLambdaFunction = new lambda.Function(this, "lambda", { - // defaults for configurable properties + // defaults runtime: lambda.Runtime.PYTHON_3_11, handler: "handler.handler", memorySize: 1024, @@ -31,9 +31,6 @@ import { file: "runtime/Dockerfile", buildArgs: { PYTHON_VERSION: '3.11' }, }), - // overwrites defaults with user-provided configurable properties - ...props.lambdaFunctionOptions, - // Non configurable properties that are going to be overwritten even if provided by the user vpc: props.vpc, vpcSubnets: props.subnetSelection, allowPublicSubnet: true, @@ -43,6 +40,8 @@ import { DB_MAX_CONN_SIZE: "1", ...props.apiEnv, }, + // overwrites defaults with user-provided configurable properties + ...props.lambdaFunctionOptions }); props.dbSecret.grantRead(this.tiPgLambdaFunction); @@ -103,7 +102,7 @@ import { /** - * Optional settings for the lambda function. Can be anything that can be configured on the lambda function, but some will be overwritten by values defined here. + * Can be used to override the default lambda function properties. * * @default - defined in the construct. */ diff --git a/lib/titiler-pgstac-api/index.ts b/lib/titiler-pgstac-api/index.ts index 7ac8fe9..726744d 100644 --- a/lib/titiler-pgstac-api/index.ts +++ b/lib/titiler-pgstac-api/index.ts @@ -39,7 +39,7 @@ import { CustomLambdaFunctionProps } from "../utils"; super(scope, id); this.titilerPgstacLambdaFunction = new lambda.Function(this, "lambda", { - // defaults for configurable properties + // defaults runtime: lambda.Runtime.PYTHON_3_11, handler: "handler.handler", memorySize: 3008, @@ -49,14 +49,13 @@ import { CustomLambdaFunctionProps } from "../utils"; file: "runtime/Dockerfile", buildArgs: { PYTHON_VERSION: '3.11' } }), - // overwrites defaults with user-provided configurable properties - ...props.lambdaFunctionOptions, - // Non configurable properties that are going to be overwritten even if provided by the user vpc: props.vpc, vpcSubnets: props.subnetSelection, allowPublicSubnet: true, // if user provided environment variables, merge them with the defaults. environment: props.apiEnv ? { ...defaultTitilerPgstacEnv, ...props.apiEnv, "PGSTAC_SECRET_ARN": props.dbSecret.secretArn } : defaultTitilerPgstacEnv, + // overwrites defaults with user-provided configurable properties + ...props.lambdaFunctionOptions, }); // grant access to buckets using addToRolePolicy @@ -132,7 +131,7 @@ import { CustomLambdaFunctionProps } from "../utils"; readonly titilerPgstacApiDomainName?: IDomainName; /** - * Optional settings for the lambda function. Can be anything that can be configured on the lambda function, but some will be overwritten by values defined here. + * Can be used to override the default lambda function properties. * * @default - defined in the construct. */ diff --git a/tox.ini b/tox.ini index 3b42230..79db331 100644 --- a/tox.ini +++ b/tox.ini @@ -23,7 +23,7 @@ exclude = __pycache__ .git .tox - venv* + *venv* toxenv* devenv* cdk.out @@ -38,7 +38,7 @@ exclude = __pycache__ .git .tox - venv* + *venv* toxenv* devenv* cdk.out