AWSLambda: publish_layer_version() should always set the code_sha_256 attr (#6920)

This commit is contained in:
Bert Blommers 2023-10-16 08:46:13 +00:00 committed by GitHub
parent 2021e564fa
commit 1f51c2f766
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 22 additions and 1 deletions

View File

@ -371,6 +371,11 @@ class LayerVersion(CloudFormationModel):
self.code_sha_256,
self.code_digest,
) = _s3_content(key)
else:
self.code_bytes = b""
self.code_size = 0
self.code_sha_256 = ""
self.code_digest = ""
@property
def arn(self) -> str:

View File

@ -1,10 +1,12 @@
import boto3
import os
import pytest
from botocore.exceptions import ClientError
from freezegun import freeze_time
from moto import mock_lambda, mock_s3
from moto import mock_lambda, mock_s3, settings
from moto.core import DEFAULT_ACCOUNT_ID as ACCOUNT_ID
from unittest import mock, SkipTest
from uuid import uuid4
from .utilities import get_role_name, get_test_zip_file1
@ -31,6 +33,20 @@ def test_publish_lambda_layers__without_content():
assert err["Message"] == "Missing Content"
@mock_lambda
@mock.patch.dict(os.environ, {"VALIDATE_LAMBDA_S3": "false"})
def test_publish_layer_with_unknown_s3_file():
if not settings.TEST_DECORATOR_MODE:
raise SkipTest("Can only set env var in DecoratorMode")
conn = boto3.client("lambda", _lambda_region)
content = conn.publish_layer_version(
LayerName=str(uuid4())[0:6],
Content=dict(S3Bucket="my-bucket", S3Key="my-key.zip"),
)["Content"]
assert content["CodeSha256"] == ""
assert content["CodeSize"] == 0
@mock_lambda
@mock_s3
@freeze_time("2015-01-01 00:00:00")