I seem to have come across a bug? Unexpected beha...
# general
c
I seem to have come across a bug? Unexpected behavior at least: I’m building a lambda function from a local zip file. I’m looping over 2 regions. But only the first region gets the updated code.
pulumi preview
etc. show that there are no changes, but when I look in the AWS dashboard I can see that one region still has the old code. This is an app with one stack that deploys to 2 region. I think the culprit is somehow this:
Copy code
code=pulumi.FileArchive("path/to/lambda.zip"),
I even tried making 2 copies of the file (one for each region), but pulumi still isn’t seeing that one of the lambdas needs to be updated. 🤔 Any ideas?
l
Can you add a text snippet with the relevant loopy code? Is it using AWS v7 or v6?
It might be that a resource is marked as deployed so it won't bother again. You shouldn't need to make a separate copy of the file, but two separate FileArchive resources might be required. But, since having two copies of the file didn't fix it, two separate FileArchives won't, either.
c
it’s sorta this:
Copy code
import pulumi
import pulumi_aws as aws
import shutil
from providers import providers
from regional.iam_role_lambda import iam_roles
from regional.s3_artifacts import s3_artifacts

cfg = pulumi.Config()
prefix = cfg.require("resourcePrefix")
regions = cfg.require_object("regions") # e.g. us-east-1, us-west-2
tags = cfg.get_object("tags") or {}

my_lambda = {}

for r in regions:
    provider = providers[r]

    # Region-specific copy of the zip;
    regional_zip_path = f"path/to/lambda_src-{r}.zip"
    shutil.copy2("path/to/lambda_src.zip", regional_zip_path)

    # The role this Lambda assumes
    role = iam_roles[r]

    # Build the Lambda function
    fn = aws.lambda_.Function(
        f"{prefix}source-builder-{r}",
        name=f"{prefix}source-builder-{r}",
        role=role.arn,
        runtime="python3.12",
        handler="index.lambda_handler",
        timeout=300,
        memory_size=256,
        code=pulumi.FileArchive(regional_zip_path),
        environment=aws.lambda_.FunctionEnvironmentArgs(
            variables={
                # ... 
            }
        ),
        tags=tags,
        opts=pulumi.ResourceOptions(
            provider=provider,
            depends_on=[
                # ... 
            ],
        ),
    )

    my_lambda[r] = fn

pulumi.export(
    "my_lambda",
    {
        r: {
            "name": my_lambda[r].name,
            "arn": my_lambda[r].arn,
        }
        for r in regions
    },
)
l
Ah, so already multiple FileArchive resources... hmm.
And other resources are being deployed correctly, using the same array of providers?
c
`pulumi preview” shows that there are no changes. I don’t know how long this has been happening… clearly the code got into the lambda somehow. AFAIK the providers have been working — buckets, ssm params, ddb tables etc. I only have one lambda function to deploy, so this is the only time i’ve used the FileArchive
l
Wondering if maybe r[1] got overwritten with r[0] somehow...
Have you inspected the regions objects? I gave up on using requireObject years ago due to unexpected things happening with arrays (probably due to my bad YAML formatting.. but they were still unexpected).
I think the only way I could help here would be to reproduce it.
And it's been over a week since I wrote anything in Pulumi.. so I will!
c
If I add
Copy code
<http://pulumi.log.info|pulumi.log.info>(f"[DEBUG] regions = {regions}")
I see what I expect, e.g.
Copy code
[DEBUG] regions = ['us-east-2', 'us-west-2']
so that appears to be working fine.
l
Yep. I'm assuming it's a Pulumi bug then. I'm going to try to reproduce
👍 1
c
For now I just updated the code in the AWS dashboard, but that makes me feel uneasy 😬
Is there a place to file bugs? @little-cartoon-10569?
fyi, my providers.py looks like this:
Copy code
# Pulumi requires unique provider refs across the entire stack, so 
# we create them once here per region.
import pulumi_aws as aws
import pulumi

cfg = pulumi.Config()
regions = cfg.require_object("regions")

providers = {r: aws.Provider(f"aws-{r}-provider", region=r) for r in regions}
l
Bugs get filed in the appropriate git repo. I don't know if this is an AWS or a core Pulumi issue.. mabye @modern-spring-15520 would be able to direct you?
I've had a go at reproducing the problem. I didn't use a loop, I just created 2 providers and 2 sets of resources at the top level. Both lambdas point at the same .mjs file (using FileArchive wrapped in AssetArchive), rather than a zip. Updates to the .mjs file were detected correctly and updated to two regions within the same account.
Perhaps the AssetArchive is necessary for this?
Our code property doesn't point to a FileArchive resource. it has this value (in Typescript):
Copy code
code: new pulumi.asset.AssetArchive({
    ".": new pulumi.asset.FileArchive(resolve(dirname(fileURLToPath(import.meta.url)), "lambda", codePath))
  });
Where codePath is a directory, for us. I presume you would use a .zip directly, not a directory.
m
https://github.com/pulumi/pulumi/issues should work, with as much details to repro as you've got.
c
Well… I put together a simple proof of concept trying to reproduce what I’m seeing, but I’m not able to reproduce it either 🤔 #sanity-check
🤔 1
w
So it’s working on the simple example?
c
Yeah. I’m gonna pour coffee on my head and see if I missed something in my main app/stack
m
I’m gonna pour coffee on my head
I think you might be using the coffee wrong 🙂
c
seems to be working everywhere now. Lambda source code is updating as expected. Pour coffee on the keyboard?
🎉 1
m
Probably threatening with coffee is enough to scare it into proper action
c
weaponized beverages is the future of code
🙌 1
💯 1