Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -156,6 +156,7 @@ Outpost infrastructure is defined as code using **AWS CDK**.

- [AWS CLI](https://aws.amazon.com/cli/) installed and configured
- Node.js installed
- [Docker](https://www.docker.com/products/docker-desktop/) running in the background (Required by AWS CDK to cross-compile Python C-extensions like `lxml` for the AWS Linux environment)

### Setup

Expand Down
26 changes: 7 additions & 19 deletions infra/lib/outpost-stack.ts
Original file line number Diff line number Diff line change
Expand Up @@ -120,28 +120,16 @@ export class OutpostStack extends cdk.Stack {

const processRunFunction = new lambda.Function(this, 'ProcessRunFunction', {
runtime: lambda.Runtime.PYTHON_3_12,
architecture: lambda.Architecture.ARM_64,
handler: 'process_run.handler',
code: lambda.Code.fromAsset(path.join(__dirname, '../../backend/python/src/handlers'), {
code: lambda.Code.fromAsset(path.join(__dirname, '../../backend/python'), {
bundling: {
image: lambda.Runtime.PYTHON_3_12.bundlingImage,
local: {
tryBundle(outputDir: string) {
try {
// Install dependencies into the output directory
execSync(
`pip3 install -r ${path.join(__dirname, '../../backend/python/requirements.txt')} -t ${outputDir}`,
);
// Copy the handler code into the output directory
execSync(
`cp -R ${path.join(__dirname, '../../backend/python/src/handlers/process_run.py')} ${outputDir}`,
);
return true;
} catch (e) {
console.warn('Local Python bundling failed:', e);
return false;
}
},
},
command: [
'bash',
'-c',
'pip install -r requirements.txt -t /asset-output --platform manylinux2014_aarch64 --only-binary=:all: && cp -R src/handlers/* /asset-output/',
],
},
}),
Comment on lines 122 to 134
Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

medium

For consistency with the Go Lambda functions in this stack which use ARM64, consider specifying the architecture for this Python function as well. ARM-based Lambdas can also provide better price/performance.

If you switch to ARM64, you'll need to update the bundling command to install the correct platform-specific wheels for your dependencies.

      runtime: lambda.Runtime.PYTHON_3_12,
      architecture: lambda.Architecture.ARM_64,
      handler: 'process_run.handler',
      code: lambda.Code.fromAsset(path.join(__dirname, '../../backend/python'), {
        bundling: {
          image: lambda.Runtime.PYTHON_3_12.bundlingImage,
          command: [
            'bash',
            '-c',
            'pip install -r requirements.txt -t /asset-output --platform manylinux2014_aarch64 --only-binary=:all: && cp -R src/handlers/* /asset-output/',
          ],
        },
      }),

environment: {
Expand Down
Loading