pulumi-aws-native
pulumi-aws-native copied to clipboard
Lambda Function doesn't support pulumi assets
In AWS classic, you can do the following:
const lambda = new awsclassic.lambda.Function("lambdaFunction", {
code: new pulumi.asset.AssetArchive({
".": new pulumi.asset.FileArchive("./app"),
}),
runtime: "nodejs12.x",
role: lambdaRole.arn,
handler: "index.handler",
});
In AWS Native you have to zip up your code first and then point the code.zipFile at the zip file you've created:
const lambdaFunction = new awsnative.lambda.Function("lambdaFunction", {
code: {
zipFile: "./app.zip",
},
runtime: "nodejs12.x",
role: lambdaRole.arn,
handler: "index.handler",
});
Expected: Be able to use the Pulumi Asset resources
For reference, here is the generated type in the native provider:
export interface FunctionCode {
/**
* ImageUri.
*/
imageUri?: string;
/**
* An Amazon S3 bucket in the same AWS Region as your function. The bucket can be in a different AWS account.
*/
s3Bucket?: string;
/**
* The Amazon S3 key of the deployment package.
*/
s3Key?: string;
/**
* For versioned objects, the version of the deployment package object to use.
*/
s3ObjectVersion?: string;
/**
* The source code of your Lambda function. If you include your function source inline with this parameter, AWS CloudFormation places it in a file named index and zips it to create a deployment package..
*/
zipFile?: string;
}
We'll need to figure out how we can augment generated types to support UX features like this.
Ok, after further testing, I'm pretty sure the aws-native example from the issue description doesn't work at all with the Cloud Control API. As far as I can tell from the API docs, the zipFile parameter only accepts inline code, not a file path.
I'll check with the AWS team to confirm, and then we can decide on the path forward for this issue.
Blocked by https://github.com/aws-cloudformation/cloudformation-coverage-roadmap/issues/970
@mikhailshilkov I assume since that issue you referenced is fixed, perhaps now this can be fixed as well?
@danielrbradley @thomas11 There is indeed a ZipFile property now:
- https://github.com/pulumi/pulumi-aws-native/blob/master/aws-cloudformation-schema/aws-lambda-function.json#L190
- https://github.com/pulumi/pulumi-aws-native/blob/master/sdk/dotnet/Lambda/Inputs/FunctionCodeArgs.cs#L43
We should take a look if it works as we need and if we can change it to be an Asset.
@mikhailshilkov I think the ZipFile property is the same one that was always there and that Levi mentioned on his comment from 10/20/21. It expects the actual source code, not a path:
The source code of your Lambda function. If you include your function source inline with this parameter, AWS CloudFormation places it in a file named index and zips it to create a deployment package.
The docs also mention only zip file or inline source as options.
Not sure why https://github.com/aws-cloudformation/cloudformation-coverage-roadmap/issues/970 that you filed was closed but I don't see any evidence of such functionality.
@thomas11 Ugh, okay, thank you for looking into that. I asked for clarification on the upstream issue but I'm not sure they monitor closed issues...
Hey team, do you know if there has been any progress on this issue?
I'm not sure it qualifies as an "enhancement", being able to ship its code for a lambda seems pretty basic. I can't find an example or a doc anywhere explaining how to do it with aws-native (except for super basic use case like having its whole code inlined in a string).
@b4stien the way to do this at the moment would be to add your zip file to an s3 bucket and pass those values in to allow the lambda service to pull from s3 instead