Updating AWS::Lambda::Function
resources
When a generated template contains AWS::Lambda::Function
resources, then warnings are generated stating that Code/S3Bucket
and Code/S3Key
properties
are identified as MUTUALLY_EXCLUSIVE_PROPERTIES
. In addition, the Code/S3ObjectVersion
property receives a UNSUPPORTED_PROPERTIES
warning. You may notice that the Code/ImageUri
and Code/ZipFile
properties are missing from the generated template. This is because these are mutually
exclusive write-only properties. Any AWS::Lambda::Function
resource can have only one of these exclusive
sets of properties:
-
Code/S3Bucket
andCode/S3Key
properties, and optionally theCode/S3ObjectVersion
property -
Code/ImageUri
property -
Code/ZipFile
property
The IaC generator cannot determine which set of exclusive write-only properties were used to create or update the
resource. As a result, the IaC generator includes only the first set of properties in the generated template. In order
to include AWS::Lambda::Function
resources in a generated template, the generated template must be
downloaded and updated with the correct information for the Lambda code.
If you store your Lambda code in an Amazon S3 bucket and do not use the
S3ObjectVersion
property, you can import the generated template without any modifications. The
IaC generator will ask you for the Amazon S3 bucket and key as template parameters during the import operation.
If you store your Lambda code as an Amazon ECR repository, you can update your template using the following instructions:
-
Download the generated template.
-
Remove the properties and corresponding parameters for the
Code/S3Bucket
andCode/S3Key
properties from the generated template. -
Replace the removed properties in the generated template with the
Code/ImageUri
property, specifying the URL for the Amazon ECR repository. -
Open the generated template in the IaC generator console and choose the Import edited template button.
If you store your Lambda code as in a zip file, you can update your template using the following instructions:
-
Download the generated template.
-
Remove the properties and corresponding parameters for the
Code/S3Bucket
andCode/S3Key
properties from the generated template. -
Replace the removed properties in the generated template with the
Code/ZipFile
property. -
Open the generated template in the IaC generator console and choose the Import edited template button.
If you don’t have a copy of your Lambda code, you can update your template using the following instructions:
-
Use the AWS Lambda
GetFunction
API action (for example, by using theaws lambda get-function
AWS CLI command. -
In the response, the
RepositoryType
parameter isS3
if the code is in a Amazon S3 bucket, orECR
if the code is in an Amazon ECR repository. -
In the response, the
Location
parameter contains a pre-signed URL that you can use to download the deployment package for 10 minutes. Download the code. -
Upload the code to a Amazon S3 bucket.
-
Run an import operation with t he generated template and provide the bucket name and key as parameter values.