pulumi-aws: InvalidParameterValueException: Uploaded file must be a non-empty zip

What happened?

From @komalali

Hi! I have noticed a recurring error as I’ve worked on drift detection.

Context:

  • I have a stack that uses the aws-serverless template: stack
  • It is deployed in the dev-sandbox account, so every night a number of these resources are cleaned up
  • The following day, when I run drift detection and remediation, the first remediation fails. link
aws:lambda:Function (fn):
    error: 1 error occurred:
    	* creating Lambda Function (fn-a91d018): operation error Lambda: CreateFunction, https response error StatusCode: 400, RequestID: b2589290-ab14-4526-a65c-3b90fabeb5e2, InvalidParameterValueException: Uploaded file must be a non-empty zip

The following drift run/remediation succeeds.

Example

The source is very simple:

https://github.com/pulumi/deploy-demos/blob/main/pulumi-programs/drift-test/index.ts

import * as pulumi from "@pulumi/pulumi";
import * as aws from "@pulumi/aws";
import * as apigateway from "@pulumi/aws-apigateway";

// A Lambda function to invoke
const fn = new aws.lambda.CallbackFunction("fn", {
    callback: async (ev, ctx) => {
        return {
            statusCode: 200,
            body: new Date().toISOString(),
        };
    }
})

// A REST API to route requests to HTML content and the Lambda function
const api = new apigateway.RestAPI("api", {
    routes: [
        { path: "/", localPath: "www"},
        { path: "/date", method: "GET", eventHandler: fn },
    ]
});

// The URL at which the REST API will be served.
export const url = api.url;

Output of pulumi about

$ pulumi about 
 Logging in using access token from PULUMI_ACCESS_TOKEN 
 CLI           
 Version      3.109.0 
 Go Version   go1.22.0 
 Go Compiler  gc 
  
 Plugins 
 NAME            VERSION 
 aws             6.25.1 
 aws-apigateway  2.4.0 
 awsx            2.5.0 
 docker          4.5.1 
 docker          3.6.1 
 nodejs          unknown 
  
 Host      
 OS       debian 
 Version  11.9 
 Arch     x86_64 
  
 This project is written in nodejs: executable='/usr/bin/node' version='v18.17.1' 
  
 Backend         
 Name           pulumi.com 
 URL            https://app.pulumi.com/komal-pulumi-corp 
 User           komal-pulumi-corp 
 Organizations  komal-pulumi-corp, service-provider-test-org, komal-testing-123, pulumi-test, pulumi 
 Token type     personal 
  
 Dependencies: 
 NAME                    VERSION 
 @pulumi/aws-apigateway  2.4.0 
 @pulumi/aws             6.25.1 
 @pulumi/awsx            2.5.0 
 @pulumi/pulumi          3.109.0 
 @types/node             18.19.24 
 typescript              4.9.5 
  
 Pulumi locates its logs in /tmp by default 
 warning: Failed to get information about the current stack: No current stack

Additional context

We tried a few times to reproduce locally but failed to do so, while it reproduces pretty consistently with deployments. This seems quite surprising. There’s a bit going about drift detection but when all is said and done deployments is simply performing this operation over a state that tracks a lambda and a cloud that has the lambda removed:

pulumi update --refresh --skip-preview --yes

Pulumi refreshes and drops the lambda from state, then decides to Create the lambda, which should succeed but does not.

Contributing

Vote on this issue by adding a 👍 reaction. To contribute a fix for this issue, leave a comment (and link to your pull request, if you’ve opened one already).

About this issue

  • Original URL
  • State: closed
  • Created 3 years ago
  • Reactions: 5
  • Comments: 18 (10 by maintainers)

Commits related to this issue

Most upvoted comments

The AssetArchive to upload gets stored as zip file in ${TEMP}/pulumi-asset-${HASH}, with ${HASH} based on the contents of the archive. When we run pulumi update --refresh and the zip files are not present yet, they get created in ${TEMP} but are empty. Presumably the name is derived from the existing state. If we then run a pulumi update that needs to do changes, it will fail with the empty zip error. Since deployments run with an empty temp folder, it reproduces all the time there, whereas locally you might have the correctly formed zip from the previous update.

triage-empty-zip main% ls -ahl /var/folders/lv/czktcqg963q26_khyypypmkm0000gn/T/pulumi-asset-*
zsh: no matches found: /var/folders/lv/czktcqg963q26_khyypypmkm0000gn/T/pulumi-asset-*
triage-empty-zip main% pulumi update --refresh --stack dev
Previewing update (dev)

View in Browser (Ctrl+O): https://app.pulumi.com/v-julien-pulumi-corp/triage-pulumi-empty-zip/dev/previews/5600a2f8-7845-477b-9348-be5846e9f152

     Type                    Name                         Plan       Info
     pulumi:pulumi:Stack     triage-pulumi-empty-zip-dev
     ├─ aws:iam:Role         iam_for_lambda
 ~   └─ aws:lambda:Function  fn                           update     [diff: ~code]

Resources:
    ~ 1 to update
    2 unchanged

Do you want to perform this update? no
confirmation declined, not proceeding with the update
triage-empty-zip main% ls -ahl /var/folders/lv/czktcqg963q26_khyypypmkm0000gn/T/pulumi-asset-*
-rw-------  1 julien  staff    22B Mar 18 21:19 /var/folders/lv/czktcqg963q26_khyypypmkm0000gn/T/pulumi-asset-4271ac265fd6fbf363faa1a179cec1a6174963b9bc656f4fb989f3b502ecaf2a
-rw-------  1 julien  staff    22B Mar 18 21:19 /var/folders/lv/czktcqg963q26_khyypypmkm0000gn/T/pulumi-asset-92b616411729aeb8d8bbb0c1d5e5c9b305ebffa1e0563a2286eefc658220c23e

Those 22B files are empty zip files.

If we run without --refresh, the zip gets created correctly

triage-empty-zip main% rm /var/folders/lv/czktcqg963q26_khyypypmkm0000gn/T/pulumi-asset-*
triage-empty-zip main% ls -ahl /var/folders/lv/czktcqg963q26_khyypypmkm0000gn/T/pulumi-asset-*
zsh: no matches found: /var/folders/lv/czktcqg963q26_khyypypmkm0000gn/T/pulumi-asset-*
triage-empty-zip main% pulumi update --stack dev
Previewing update (dev)

View in Browser (Ctrl+O): https://app.pulumi.com/v-julien-pulumi-corp/triage-pulumi-empty-zip/dev/previews/0c1d95bc-27f1-4d90-907b-add516e73a52

     Type                    Name                         Plan       Info
     pulumi:pulumi:Stack     triage-pulumi-empty-zip-dev
 ~   └─ aws:lambda:Function  fn                           update     [diff: ~code]

Resources:
    ~ 1 to update
    2 unchanged

Do you want to perform this update? no
confirmation declined, not proceeding with the update
triage-empty-zip main% ls -ahl /var/folders/lv/czktcqg963q26_khyypypmkm0000gn/T/pulumi-asset-*
-rw-------  1 julien  staff   201B Mar 18 21:19 /var/folders/lv/czktcqg963q26_khyypypmkm0000gn/T/pulumi-asset-92b616411729aeb8d8bbb0c1d5e5c9b305ebffa1e0563a2286eefc658220c23e

Note the fileize of 201B this time around.

We’re seeing a resurgence of this issue – we upgraded from Pulumi 3.38.0 to 3.142.0 a few weeks ago to mitigate this same issue, and after a few weeks, we’ve now noticed that we’re consistently running into the InvalidParameterValueException: Uploaded file must be a non-empty zip in seemingly random packages packages.

We’re running: pulumi up --yes --refresh --diff --stack stack.name.env --refresh=true, with the AWS v6.18.2 plugin.

Please let me know if you’d like for me to create a new issue instead.

Local reproduction:

  1. Deploy a lambda (note that the newly created ${TEMP}/pulumi-asset-${HASH} file is larger than 22B)
  2. Delete ${TEMP}/pulumi-asset-${HASH}
  3. Edit the code of the lambda
  4. pulumi up --refresh --stack dev (this will re-create the file for the previous hash, but as an empty zip file)
  5. Revert the code edit (code needs to be exactly as in step 1, so the hash matches)
  6. pulumi up --stack dev

The last step will attempt to upload the empty zip file.