Skip to content

Checksum updated when code fails to deploy #165

@joshdcuneo

Description

@joshdcuneo

When updating a function the checksum of the new version is added to the description. Then the configuration (including the description) is updated, followed by the code.

If the call to update the function code fails, for example due to a network issue, the checksum is still updated. This makes all future deployments of the same code a noop even though the code had not been deployed.

// vendor/hammerstone/sidecar/src/Clients/LambdaClient.php

/**
 * @return int
 *
 * @throws Exception
 */
public function updateExistingFunction(LambdaFunction $function)
{
    $config = $function->toDeploymentArray();
    dd(json_encode($config));
    // Since the code package has a unique name, this checksum
    // encompasses both the code and the configuration.
    $checksum = substr(md5(json_encode($config)), 0, 8);

    // See if the function already exists with these *exact* parameters.
    if ($this->functionExists($function, $checksum)) {
        return self::NOOP;
    }

    // Add the checksum to the description, so we can look for it next time.
    $config['Description'] .= " [$checksum]";

    // For the updateFunctionCode call, AWS requires that the S3Bucket
    // and S3Key be top level instead of nested under `Code`.
    $code = [
        'FunctionName' => $config['FunctionName'],
        'Publish' => $config['Publish'],
        'Architectures' => $config['Architectures'],
    ];

    if ($function->packageType() === 'Zip') {
        $code['S3Bucket'] = $config['Code']['S3Bucket'];
        $code['S3Key'] = $config['Code']['S3Key'];
    } else {
        $code = array_merge($code, $function->package());
    }

    $config = Arr::except($config, ['Code', 'Publish']);

    $this->updateFunctionConfiguration($config);
    $this->updateFunctionCode($code);               // <=== failures here break future deploys
}

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions