I'm really struggling with how to create an aws La...
# general
p
I'm really struggling with how to create an aws Lambda Archive that does NOT include the folders between the "workdir" and the files i'm trying to include in the archive. Consider this folder structure:
Copy code
pulumi.yaml
pretokengeneration/dist/{bunch of files to archive}
What I need is to create an archive that ONLY includes the files in
pretokengeneration/dist/
without the parent folder structure. Hoisting the files to the root of the zip file. I keep getting this structure that includes all paths from "work dir" to where the files are and it blows up in aws lambda. I've scoured the internets... and pulumi community. For some reason this is either so obvious that no one has ever asked this question, or I'm doing something really stupid.
I've tried many combinations of prefixes and values for
dir
to see if I could generate the desired zip file but to no avail:
Copy code
const lambdaBuild = local.runOutput({
		dir: "pretokengeneration",
		command: `cd src && npm install && tsc`,
		archivePaths: ["dist/**", "!dist/**/test/**"]
	});

...
     // then I provide it to pulumi.aws.Function like this
     code: lambdaBuild.archive,
@aloof-bear-23820/ @proud-winter-66045 looks like no traction 😞
b
Hi Bruce, is there any reason you can’t do this:
Copy code
const fn = new aws.lambda.Function("fn", {
    code: new pulumi.asset.AssetArchive({
        ".": new pulumi.asset.FileArchive("./dist")
    },
    ... rest of lambda
});
I think that should work
p
I saw that usage elsewhere and tried it. Pretty sure it didn't work as I'd hoped. I can try again in a bit...
and thank you for responding!
b
That’s how I usually do this
p
Still showing as nested in lambda. Is there a way to inspect the generated archive locally without having to upload to aws during debugging?
b
You’re using what looks like JavaScript/typescript to define your resources. Use those tools to read the directory structure and you can log them to the screen
So I think it’s the archive paths input in the command resource that’s doing this. Can you not use that and use the assets.archive bit in the function resource to zip it up?
p
I am using Typescript. In the debugger I see this. Not sure what "use those tools to read the directory structure" means?
The pulumi approach of using but not using Promises is quite confusing.
pulumi.log.info() is demanding a "Resource" but these operations provide
FileArchive
so not sure how to understand what they actually resolve to.
@brave-planet-10645 I can find "archivePaths" in my Typescript, but you are losing me with the rest of this statement:
So I think it’s the archive paths input in the command resource that’s doing this. Can you not use that and use the assets.archive bit in the function resource to zip it up?
What is an "assets.archive" bit? What is a "function resource"? Is that the Lambda defn?
I'm trying exactly what you described - ignoring the
local.runOutput
approach.
Copy code
const fn = new aws.lambda.Function("fn", {
    code: new pulumi.asset.AssetArchive({
        ".": new pulumi.asset.FileArchive("./dist")
    },
    ... rest of lambda
});
The resulting archive from this seems to include the
./dist
folder structure in it:
Copy code
new pulumi.asset.AssetArchive({
        ".": new pulumi.asset.FileArchive("./dist")
    },
should I just use bash and zip tooling that I understand? This is really frustrating.
q
Bruce, have you tried the built in file handling fom Typescript/Javascript for this? As an example: https://stackoverflow.com/questions/62031171/file-handling-in-typescript
p
I know how to work with Typescript. It's the pulumi libraries that are opaque to me.
So if bypassing Pulumi for this is the recommendation, then I'll do that. It just seems like this should be "pretty easy" since this is a common work flow and I see examples of other people using this online. I guess they all just dump the typescript artifacts into the folder that contains
pulumi.yaml
b
This is my usual approach to deploying lambdas with api gateway https://github.com/pierskarsenbarg/useful-pulumi/tree/main/api-gateway-lambda lines 15-16 of index.ts is how I’ve done the file handling and the files uploaded are in the
app
folder.
In this case I’m just uploading a JavaScript lambda with no preprocessing (so no typescript-JavaScript compiling)
p
Thank you for sharing the example. That should be easily adapted to include the Typescript=>Javascript preprocessing step without issue. So the resulting archive contains just
index.js
and
package.json
at the root? Then my issue is somewhere else like: • i'm not looking at the archive I think I'm looking at • linux is doing something different than other platforms • some other simple failure on my end.
I do appreciate your time here. Just getting a bit frustrated but that is not your problem.
b
It doesn’t have to contain the index.js and the package.json, that’s just my example for a super simple lambda
p
i get that - just clarifying that the contents of the
./app
folder are appearing in the root of the archive and not in an
app
folder in the archive.
b
That’s correct
p
@brave-planet-10645 so looks like the UI in
aws
is misrepresenting what is in the package. When I downloaded the archive (export function) it looks correct!!!
Now I just need to ensure that my
tsc
step is triggered reliably before the archive is created. Trying to to figure out how a
Output<runResult>
can be used as a DependsOn (it only accepts
Input<Resource>
types).
b
Personally I would have the build as a step in your CI/CD pipeline pre-Pulumi. Then you can store the output as an artifact that can be accessed at a later time if necessary. I’ve got a demo of how I use Pulumi and webpack to build a mono-repo: https://github.com/pierskarsenbarg/useful-pulumi/tree/main/serverless-webpack
p
Sounds like there is no way to depend on the output of runResult. Not sure what value it provides then. I'll try your approach.
b
What’s the
runResult
coming from?