skip to Main Content

Currently using DockerImageFunction, but I can’t figure out how to set the CMD Override. Any advice would be appreciated.

Repo: https://github.com/alphaHades/Dockerized-Lambda-NR/blob/main/lib/docker-lambda-aws-stack.ts

enter image description here

2

Answers


  1. Chosen as BEST ANSWER

    // docker image function const dockerFunc = new lambda.DockerImageFunction(this, "DockerFunc", { 
    code: lambda.DockerImageCode.fromImageAsset( "./image", { 
          cmd: ['newrelic_lambda_wrapper.handler'] // assign cmd override for image config } ),
    
    });


  2. Here’s an example which is taken directly from the CDK documentation. It contains all relevant features, but importantly shows how to set cmd:

    // The code below shows an example of how to instantiate this type.
    // The values are placeholders you should change.
    import * as cdk from 'aws-cdk-lib';
    import { aws_ecr_assets as ecr_assets } from 'aws-cdk-lib';
    import { aws_lambda as lambda } from 'aws-cdk-lib';
    
    declare const networkMode: ecr_assets.NetworkMode;
    declare const platform: ecr_assets.Platform;
    const assetImageCodeProps: lambda.AssetImageCodeProps = {
      assetName: 'assetName',
      buildArgs: {
        buildArgsKey: 'buildArgs',
      },
      buildSecrets: {
        buildSecretsKey: 'buildSecrets',
      },
      buildSsh: 'buildSsh',
      cacheFrom: [{
        type: 'type',
    
        // the properties below are optional
        params: {
          paramsKey: 'params',
        },
      }],
      cacheTo: {
        type: 'type',
    
        // the properties below are optional
        params: {
          paramsKey: 'params',
        },
      },
      cmd: ['cmd'],
      entrypoint: ['entrypoint'],
      exclude: ['exclude'],
      extraHash: 'extraHash',
      file: 'file',
      followSymlinks: cdk.SymlinkFollowMode.NEVER,
      ignoreMode: cdk.IgnoreMode.GLOB,
      invalidation: {
        buildArgs: false,
        buildSecrets: false,
        buildSsh: false,
        extraHash: false,
        file: false,
        networkMode: false,
        outputs: false,
        platform: false,
        repositoryName: false,
        target: false,
      },
      networkMode: networkMode,
      outputs: ['outputs'],
      platform: platform,
      target: 'target',
      workingDirectory: 'workingDirectory',
    };
    

    https://docs.aws.amazon.com/cdk/api/v2/docs/aws-cdk-lib.aws_lambda.AssetImageCodeProps.html

    Login or Signup to reply.
Please signup or login to give your own answer.
Back To Top
Search