### Clean and Install Dependencies Source: https://github.com/aws-solutions/dynamic-image-transformation-for-amazon-cloudfront/blob/main/README.md Clean existing dependencies and install new ones using npm. This is typically done before building or deploying. ```bash npm run clean:install ``` -------------------------------- ### Install E2E Test Dependencies Source: https://github.com/aws-solutions/dynamic-image-transformation-for-amazon-cloudfront/blob/main/source/admin-ui/src/e2e-tests/README.md Navigate to the e2e-tests directory and install project dependencies using npm. This command should be run before executing any tests. ```bash # Navigate to the e2e-tests directory cd source/admin-ui/src/e2e-tests # Install dependencies npm install ``` -------------------------------- ### Clone Repository and Set Environment Variable Source: https://github.com/aws-solutions/dynamic-image-transformation-for-amazon-cloudfront/blob/main/README.md Clone the solution repository and set the MAIN_DIRECTORY environment variable to the project's root path. This is the initial setup step for customization. ```bash git clone https://github.com/aws-solutions/dynamic-image-transformation-for-amazon-cloudfront.git cd dynamic-image-transformation-for-amazon-cloudfront export MAIN_DIRECTORY=$PWD ``` -------------------------------- ### Page Object Model Example Source: https://github.com/aws-solutions/dynamic-image-transformation-for-amazon-cloudfront/blob/main/source/admin-ui/src/e2e-tests/README.md Demonstrates the Page Object Model pattern for organizing test automation code. This example shows how to define methods for interacting with the Mapping page. ```typescript // Example: MappingPage.ts export class MappingPage { static navigateToMappings() { cy.get('a[href="/mappings"]').click(); } static clickCreateMapping() { cy.get('button').contains('Create mapping').click(); } static fillMappingForm(data: MappingTestData) { // Form filling logic } } ``` -------------------------------- ### Build ECR Image and Deploy Management Stack Source: https://github.com/aws-solutions/dynamic-image-transformation-for-amazon-cloudfront/blob/main/source/constructs/lib/v8/README.md Builds a Docker ECR image and deploys the management stack using AWS CDK. Ensure Docker is installed locally and AWS credentials are configured. ```bash cd source/constructs aws ecr-public get-login-password --region us-east-1 | docker login --username AWS --password-stdin public.ecr.aws # Management stack (deployment time ~15 mins) overrideWarningsEnabled=false npx cdk deploy v8-Stack --parameters AdminEmail="myEmail" ``` -------------------------------- ### Test Data Factory Example Source: https://github.com/aws-solutions/dynamic-image-transformation-for-amazon-cloudfront/blob/main/source/admin-ui/src/e2e-tests/README.md Illustrates the use of Test Data Factories to generate consistent and reusable test data. This example shows a factory for creating basic mapping test data. ```typescript // Example: MappingFactory.ts export class MappingFactory { static createBasicMapping(): MappingTestData { return { name: 'Test Mapping', description: 'Basic mapping for testing', hostHeaderPattern: 'example.com', origin: 'Test Origin' }; } } ``` -------------------------------- ### Bootstrap AWS CDK Environment Source: https://github.com/aws-solutions/dynamic-image-transformation-for-amazon-cloudfront/blob/main/README.md Initialize the AWS CDK environment for deployment. Ensure you have the correct AWS profile configured. ```bash overrideWarningsEnabled=false npx cdk bootstrap --profile ``` -------------------------------- ### Deploy Lambda Architecture Stack Source: https://github.com/aws-solutions/dynamic-image-transformation-for-amazon-cloudfront/blob/main/README.md Deploy the Lambda-based architecture stack (v7). This requires specifying whether to deploy a demo UI and the source bucket names. ```bash overrideWarningsEnabled=false npx cdk deploy v7-Stack\n --parameters DeployDemoUIParameter=Yes\n --parameters SourceBucketsParameter=\n --profile ``` -------------------------------- ### Set Environment Variables and Run E2E Tests Source: https://github.com/aws-solutions/dynamic-image-transformation-for-amazon-cloudfront/blob/main/source/container/test/e2e/README.md Configure necessary environment variables for region, stack name, and optional S3 buckets before executing the end-to-end tests. The SKIP_SETUP variable can be used to bypass DynamoDB seeding and ECS deployment waits for faster iteration. ```bash export CURRENT_STACK_REGION=us-east-1 export CURRENT_STACK_NAME=v8-Stack export TEST_BUCKET=my-existing-bucket export EXTERNAL_ORIGIN_BUCKET=my-external-bucket # Not currently used or provisioned. Might want to use nginx on an ec2 instance instead. export SKIP_SETUP=true npm run test:e2e ``` -------------------------------- ### Run Unit Tests for Customizations Source: https://github.com/aws-solutions/dynamic-image-transformation-for-amazon-cloudfront/blob/main/README.md Execute unit tests after making changes to ensure customizations are valid. This script should be run from the deployment directory. ```bash cd $MAIN_DIRECTORY/deployment chmod +x run-unit-tests.sh && ./run-unit-tests.sh ``` -------------------------------- ### Run Unit Tests Source: https://github.com/aws-solutions/dynamic-image-transformation-for-amazon-cloudfront/blob/main/source/v8-custom-resource/README.md Execute unit tests for the V8 custom resource using npm. ```bash npm test ``` -------------------------------- ### Run Specific Unit Test File Source: https://github.com/aws-solutions/dynamic-image-transformation-for-amazon-cloudfront/blob/main/source/management-lambda/README.md Executes a single unit test file using npm. Useful for targeted testing during development. ```bash npm test -- transformation-policy-dao.test.ts ``` -------------------------------- ### Deploy ECS Architecture Stack Source: https://github.com/aws-solutions/dynamic-image-transformation-for-amazon-cloudfront/blob/main/README.md Deploy the ECS-based architecture stack (v8). This requires an administrator email for configuration. ```bash overrideWarningsEnabled=false npx cdk deploy v8-Stack --parameters AdminEmail= ``` -------------------------------- ### Run Image Processing Stack Unit Tests Source: https://github.com/aws-solutions/dynamic-image-transformation-for-amazon-cloudfront/blob/main/source/constructs/lib/v8/README.md Execute unit tests for the image processing stack using Jest. Ensure you are in the root directory of the project. ```bash npx jest test/image-processing-stack.test.ts ``` -------------------------------- ### Run All E2E Tests (Headless) Source: https://github.com/aws-solutions/dynamic-image-transformation-for-amazon-cloudfront/blob/main/source/admin-ui/src/e2e-tests/README.md Execute all end-to-end tests in headless mode using the 'cypress:run' npm script. This is suitable for CI environments. ```bash npm run cypress:run ``` -------------------------------- ### Run E2E Tests with UI (Interactive) Source: https://github.com/aws-solutions/dynamic-image-transformation-for-amazon-cloudfront/blob/main/source/admin-ui/src/e2e-tests/README.md Launch the Cypress Test Runner UI to interactively run tests. This is useful for debugging and development. ```bash npm run cypress:open ``` -------------------------------- ### Run Specific Test Suites with Cypress Source: https://github.com/aws-solutions/dynamic-image-transformation-for-amazon-cloudfront/blob/main/source/admin-ui/src/e2e-tests/README.md Execute specific test suites by providing the file path to the Cypress run command. This allows for targeted testing of origins, mappings, or transformation policies. ```bash # Run all origin tests npx cypress run --spec "cypress/specs/origin/**/*.cy.ts" # Run specific origin test npx cypress run --spec "cypress/specs/origin/origin-create-delete.cy.ts" # Run all mapping tests npx cypress run --spec "cypress/specs/mapping/**/*.cy.ts" # Run specific mapping test npx cypress run --spec "cypress/specs/mapping/mapping-types.cy.ts" # Run all transformation policy tests npx cypress run --spec "cypress/specs/transformation-policy/**/*.cy.ts" # Run comprehensive transformation test npx cypress run --spec "cypress/specs/transformation-policy/transformation-all-options.cy.ts" ``` -------------------------------- ### Run E2E Tests by Tags Source: https://github.com/aws-solutions/dynamic-image-transformation-for-amazon-cloudfront/blob/main/source/admin-ui/src/e2e-tests/README.md Filter and run tests based on assigned tags using the --env TAGS option. This allows for executing specific test categories like 'smoke' or 'crud'. ```bash # Run only smoke tests npx cypress run --env TAGS="@smoke" # Run only CRUD tests npx cypress run --env TAGS="@crud" ``` -------------------------------- ### Run All End-to-End Tests Source: https://github.com/aws-solutions/dynamic-image-transformation-for-amazon-cloudfront/blob/main/source/management-lambda/README.md Executes all end-to-end tests. Requires deployed stack and AWS credentials. Set region and stack name via environment variables. ```bash CURRENT_STACK_REGION={myRegion} CURRENT_STACK_NAME={myStackName} npm run test:e2e ``` -------------------------------- ### Run Specific End-to-End Test Suite Source: https://github.com/aws-solutions/dynamic-image-transformation-for-amazon-cloudfront/blob/main/source/management-lambda/README.md Executes a specific end-to-end test suite. Requires deployed stack and AWS credentials. Specify region and stack name. ```bash CURRENT_STACK_REGION=us-east-1 CURRENT_STACK_NAME=my-stack npm run test:e2e -- policies.test.ts ``` -------------------------------- ### Run End-to-End Negative/Authorization Tests Source: https://github.com/aws-solutions/dynamic-image-transformation-for-amazon-cloudfront/blob/main/source/management-lambda/README.md Executes only the negative and authorization test cases for end-to-end testing. Requires deployed stack and AWS credentials. ```bash CURRENT_STACK_REGION=us-east-1 CURRENT_STACK_NAME=my-stack npm run test:e2e -- negative.test.ts ``` -------------------------------- ### Run Management Stack Unit Tests Source: https://github.com/aws-solutions/dynamic-image-transformation-for-amazon-cloudfront/blob/main/source/constructs/lib/v8/README.md Execute unit tests for the management stack using Jest. Ensure you are in the root directory of the project. ```bash npx jest test/management-stack.test.ts ``` -------------------------------- ### Run End-to-End Tests Source: https://github.com/aws-solutions/dynamic-image-transformation-for-amazon-cloudfront/blob/main/source/constructs/lib/v8/README.md Executes end-to-end tests for the deployed stacks. Requires AWS credentials to be configured locally and the management stack to be deployed. ```bash STACK_REGION={myRegion} STACK_NAME={myStack} TEST_TYPE=e2e npx jest e2e.test.ts ``` -------------------------------- ### Verify Environment Variables and AWS Credentials Source: https://github.com/aws-solutions/dynamic-image-transformation-for-amazon-cloudfront/blob/main/source/admin-ui/src/e2e-tests/README.md Use these commands to check if your environment variables for Cognito User Pool ID and App URL are set correctly, and to verify your AWS credentials. ```bash # Verify environment variables are set echo $COGNITO_USER_POOL_ID echo $APP_URL # Check AWS credentials aws sts get-caller-identity ``` -------------------------------- ### Set Environment Variables for E2E Tests Source: https://github.com/aws-solutions/dynamic-image-transformation-for-amazon-cloudfront/blob/main/source/admin-ui/src/e2e-tests/README.md Export necessary environment variables for Cognito configuration, application URL, and AWS credentials before running tests. Ensure the user password is set for authentication. ```bash # Cognito Configuration export COGNITO_ACCOUNT="your-aws-account-id" export COGNITO_USER_POOL_ID="user-pool-id" export COGNITO_REGION="your-deployed-region" # Application URL export APP_URL="https://your-app-domain.com" # AWS Credentials (if not using default profile) export AWS_ACCESS_KEY_ID="your-access-key" export AWS_SECRET_ACCESS_KEY="your-secret-key" export AWS_SESSION_TOKEN="your-session-token" # If using temporary credentials # Password for the test user to run tests export USER_PASSWORD="your_password" # example: TempPassword1234! ``` -------------------------------- ### Management Lambda API Endpoints Source: https://github.com/aws-solutions/dynamic-image-transformation-for-amazon-cloudfront/blob/main/source/management-lambda/README.md This section details the available API endpoints for managing transformation policies, origins, and mappings. All list endpoints support pagination via the `nextToken` query parameter. ```APIDOC ## Transformation Policies API ### Description Manage image transformation policies that define how images are processed. ### Method GET ### Endpoint /policies ### Query Parameters - **nextToken** (string) - Optional - Token for retrieving the next page of results. ### Response #### Success Response (200) - **items** (array) - List of transformation policies. - **nextToken** (string) - Optional - Token for retrieving the next page of results. ### Method POST ### Endpoint /policies ### Description Create a new transformation policy with JSON configuration. ### Method GET ### Endpoint /policies/{policyId} ### Description Get specific transformation policy details. ### Method PUT ### Endpoint /policies/{policyId} ### Description Update an existing transformation policy. ### Method DELETE ### Endpoint /policies/{policyId} ### Description Delete a transformation policy. ## Origins API ### Description Manage origin configurations that define source locations for images. ### Method GET ### Endpoint /origins ### Query Parameters - **nextToken** (string) - Optional - Token for retrieving the next page of results. ### Response #### Success Response (200) - **items** (array) - List of origin configurations. - **nextToken** (string) - Optional - Token for retrieving the next page of results. ### Method POST ### Endpoint /origins ### Description Create a new origin configuration. ### Method GET ### Endpoint /origins/{originId} ### Description Get specific origin configuration details. ### Method PUT ### Endpoint /origins/{originId} ### Description Update an existing origin configuration. ### Method DELETE ### Endpoint /origins/{originId} ### Description Delete an origin configuration. ## Mappings API ### Description Manage path-based or host-header based routing to map requests to specific origins. ### Method GET ### Endpoint /mappings ### Query Parameters - **nextToken** (string) - Optional - Token for retrieving the next page of results. ### Response #### Success Response (200) - **items** (array) - List of mappings. - **nextToken** (string) - Optional - Token for retrieving the next page of results. ### Method POST ### Endpoint /mappings ### Description Create a new mapping. ### Method GET ### Endpoint /mappings/{mappingId} ### Description Get specific mapping details. ### Method PUT ### Endpoint /mappings/{mappingId} ### Description Update an existing mapping. ### Method DELETE ### Endpoint /mappings/{mappingId} ### Description Delete a mapping. ``` -------------------------------- ### API Response Pagination Format Source: https://github.com/aws-solutions/dynamic-image-transformation-for-amazon-cloudfront/blob/main/source/management-lambda/README.md Illustrates the standard JSON response format for list endpoints, including items and an optional token for pagination. ```json { "items": [...], "nextToken": "optional-token-for-next-page" } ``` -------------------------------- ### DynamoDB Origin Schema Source: https://github.com/aws-solutions/dynamic-image-transformation-for-amazon-cloudfront/blob/main/source/management-lambda/README.md Defines the schema for origins, including origin name, domain, path, and headers. ```bash {} PK: "{originId}", GSI1PK: "ORIGIN", GSI1SK: "{originName}", Data: { originName: string, originDomain: string, // Validated domain name originPath?: string, originHeaders?: Record } } ``` -------------------------------- ### DynamoDB Mapping Schema Source: https://github.com/aws-solutions/dynamic-image-transformation-for-amazon-cloudfront/blob/main/source/management-lambda/README.md Defines the schema for path and host header mappings, linking patterns to origins and policies. ```bash {} PK: "{mappingId}", GSI1PK: "PATH_MAPPING" | "HOST_HEADER_MAPPING", GSI1SK: "{pattern}", GSI2PK: "ORIGIN#{originId}", // For querying by origin GSI3PK?: "POLICY#{policyId}", // For querying by policy Data: { originId: string, policyId?: string } } ``` -------------------------------- ### DynamoDB Transformation Policy Schema Source: https://github.com/aws-solutions/dynamic-image-transformation-for-amazon-cloudfront/blob/main/source/management-lambda/README.md Defines the schema for transformation policies, including policy name, transformation JSON, and default policy flag. ```bash {} PK: "{policyId}", GSI1PK: "POLICY", GSI1SK: "{policyName}", GSI2PK?: "DEFAULT_POLICY", // Only for default policy Data: { policyName: string, description?: string, policyJSON: string, // JSON string of transformations isDefault: boolean } } ``` -------------------------------- ### Route Definitions for Management API Source: https://github.com/aws-solutions/dynamic-image-transformation-for-amazon-cloudfront/blob/main/source/management-lambda/README.md Defines the API endpoints including HTTP methods, paths, and associated handler functions for managing transformation policies, origins, and mappings. ```typescript export const routes: { method: Method; path: string; handler: LambdaHandler; }[] = [ // Transformation Policies { method: "GET", path: "/policies", handler: ... }, { method: "POST", path: "/policies", handler: ... }, { method: "GET", path: "/policies/{policyId}", handler: ... }, // ... Origins and Mappings routes ]; ``` -------------------------------- ### DynamoDB Generic Entity Structure Source: https://github.com/aws-solutions/dynamic-image-transformation-for-amazon-cloudfront/blob/main/source/management-lambda/README.md Defines the generic structure for entities stored in DynamoDB, including primary keys, secondary indexes, and timestamps. ```bash {} PK: "{entityId}", // Primary Key GSI1PK: "{ENTITY_TYPE}", // Entity type for listing GSI1SK: "{sortableField}", // Sort key (name, pattern, etc.) CreatedAt: "ISO_DATE_STRING", // Creation timestamp UpdatedAt?: "ISO_DATE_STRING", // Last update timestamp Data: { // Entity-specific data // ... entity fields } } ``` -------------------------------- ### Lambda Handler with Middy Middleware Source: https://github.com/aws-solutions/dynamic-image-transformation-for-amazon-cloudfront/blob/main/source/management-lambda/README.md The Lambda handler is configured with the Middy middleware framework for request processing, including header normalization, CORS, security headers, error handling, and routing. ```typescript export const handler = middy() .use(httpHeaderNormalizer()) // Normalize HTTP headers .use(cors()) // Enable CORS .use(httpSecurityHeaders()) // Add security headers .use(errorHandler()) // Custom error handling middleware .handler(httpRouterHandler(routes)); ``` -------------------------------- ### TypeScript Error Codes Source: https://github.com/aws-solutions/dynamic-image-transformation-for-amazon-cloudfront/blob/main/source/management-lambda/README.md Defines a set of constants for error codes used in the application, facilitating consistent error handling. ```typescript const ErrorCodes = { BAD_REQUEST: "BAD_REQUEST", INVALID_JSON: "INVALID_JSON", MISSING_REQUIRED_FIELD: "MISSING_REQUIRED_FIELD", INVALID_FIELD_VALUE: "INVALID_FIELD_VALUE", NOT_FOUND: "NOT_FOUND", POLICY_NOT_FOUND: "POLICY_NOT_FOUND", ORIGIN_NOT_FOUND: "ORIGIN_NOT_FOUND", INTERNAL_SERVER_ERROR: "INTERNAL_SERVER_ERROR", }; ``` === COMPLETE CONTENT === This response contains all available snippets from this library. No additional content exists. Do not make further requests.