cdk-stacksets icon indicating copy to clipboard operation
cdk-stacksets copied to clipboard

Cannot find asset with NodejsFunction created asset

Open mbergkvist opened this issue 1 year ago • 10 comments

I trying to deploy a NodejsFunction with a stackset but I can't get the file asset to work. I get the following error

Error: Cannot find asset at /Users/markus/src/awsCore-tagScheduler/infrastructure/cdk.out/assembly-awsCoreTagScheduler-awsCoreTagScheduler-frankfurt-dev/Users/markus/src/awsCore-tagScheduler/infrastructure

It looks like it's adding the asset directory as source to the bucketDeployment instead of the asset filename. Can't figure out why though.

How to reproduce

A simplified example of what I'm trying to accomplish, more or less following the example in the project README.

export class TagSchedulerStage extends Stage {
  constructor(
    scope: Construct,
    id: string,
    props: StageProps,
  ) {
    super(scope, id, props);

    const bucketStack = new Stack(this, 'BucketStack');
    const bucket = new s3.Bucket(bucketStack, 'Assets', {
      bucketName: 'cdkstacket-asset-bucket-xyz',
    });
    bucket.addToResourcePolicy(
      new iam.PolicyStatement({
        actions: ['s3:Get*', 's3:List*'],
        resources: [bucket.arnForObjects('*'), bucket.bucketArn],
        principals: [new iam.OrganizationPrincipal('ou-ab12')],
      }),
    );

    const stack = new Stack(this, 'TopLevelStack');

    const stackSetStack = new StackSetStack(stack, 'MyStackSetStack', {
      assetBucket: bucket,
    });

    new lambdaNodejs.NodejsFunction(
      stackSetStack,
      'MyLambdaHandler',
      {
        handler: 'handler',
        entry: path.join(__dirname, '../../src/function.ts'),
      },
    );

    new StackSet(stack, 'MyStackSet', {
      capabilities: [Capability.IAM],
      deploymentType: DeploymentType.serviceManaged(),
      target: StackSetTarget.fromAccounts({
        regions: ['eu-central-1'],
        accounts: ['123456789012'],
      }),
      template: StackSetTemplate.fromStackSetStack(stackSetStack),
    });
  }
}

Any advice?

mbergkvist avatar Oct 27 '23 09:10 mbergkvist