I have a Powershell Lambda that I would like to deploy via the AWS CDK however I'm having issues getting it to run.
Deploying the Powershell via a manual Publish-AWSPowerShellLambda works:
Publish-AWSPowerShellLambda -ScriptPath .\PowershellLambda.ps1 -Name PowershellLambda
However the same script deployed with the CDK doesnt log to CloudWatch Logs, even though it has permission:
import events = require('@aws-cdk/aws-events');
import targets = require('@aws-cdk/aws-events-targets');
import lambda = require('@aws-cdk/aws-lambda');
import cdk = require('@aws-cdk/core');
export class LambdaCronStack extends cdk.Stack {
constructor(app: cdk.App, id: string) {
super(app, id);
const lambdaFn = new lambda.Function(this, 'Singleton', {
code: new lambda.AssetCode('./PowershellLambda/PowershellLambda.zip'),
handler: 'PowershellLambda::PowershellLambda.Bootstrap::ExecuteFunction',
timeout: cdk.Duration.seconds(300),
runtime: lambda.Runtime.DOTNET_CORE_2_1
});
const rule = new events.Rule(this, 'Rule', {
schedule: events.Schedule.expression('rate(1 minute)')
});
rule.addTarget(new targets.LambdaFunction(lambdaFn));
}
}
const app = new cdk.App();
new LambdaCronStack(app, 'LambdaCronExample');
app.synth();
The powershell script currently contains just the following lines and works when deployed by Publish-AWSPowerShellLambda on the CLI:
#Requires -Modules @{ModuleName='AWSPowerShell.NetCore';ModuleVersion='3.3.335.0'}
Write-Host "Powershell Lambda Executed"
Note: For the CDK Deployment I generate the .zip file using a build step in package.json:
"scripts": {
"build": "tsc",
"build-package": "pwsh -NoProfile -ExecutionPolicy Unrestricted -command New-AWSPowerShellLambdaPackage -ScriptPath './PowershellLambda/PowershellLambda.ps1' -OutputPackage ./PowershellLambda/PowershellLambda.zip",
"watch": "tsc -w",
"cdk": "cdk"
}
The CDK deploys fine and the Lambda runs as expected but the only thing in Cloudwatch Logs is this: START RequestId: 4c12fe1a-a9e0-4137-90cf-747b6aecb639 Version: $LATEST
I've checked that the Handler in the CDK script matches the output of the Publish-AWSPowerShellLambda and that the zip file uploaded fine and contains the correct code.
Any suggestions as to why this isnt working?