Skip to content
This repository was archived by the owner on Jan 28, 2025. It is now read-only.

Commit c985fe4

Browse files
committed
update tags only if defined, update readme
1 parent a46f0cf commit c985fe4

File tree

4 files changed

+28
-24
lines changed

4 files changed

+28
-24
lines changed

README.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -503,6 +503,7 @@ The fourth cache behaviour handles next API requests `api/*`.
503503
| roleArn | `string\|object` | null | The arn of role that will be assigned to both lambdas. |
504504
| runtime | `string\|object` | `nodejs12.x` | When assigned a value, both the default and api lambdas will be assigned the runtime defined in the value. When assigned to an object, values for the default and api lambdas can be separately defined |
505505
| memory | `number\|object` | `512` | When assigned a number, both the default and api lambdas will be assigned memory of that value. When assigned to an object, values for the default and api lambdas can be separately defined |
506+
| tags | `object` | `undefined` | Tags to assign to a Lambda. If undefined, the component will not update any tags. If set to an empty object, it will remove all tags. |
506507
| timeout | `number\|object` | `10` | Same as above |
507508
| handler | `string` | `index.handler` | When assigned a value, overrides the default function handler to allow for configuration. Copies `handler.js` in route into the Lambda folders. Your handler MUST still call the `default-handler` afterwards or your function won't work with Next.JS |
508509
| name | `string\|object` | / | When assigned a string, both the default and api lambdas will assigned name of that value. When assigned to an object, values for the default and api lambdas can be separately defined |

packages/serverless-components/aws-lambda/serverless.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -41,7 +41,7 @@ const defaults = {
4141
runtime: "nodejs10.x",
4242
env: {},
4343
region: "us-east-1",
44-
tags: {}
44+
tags: undefined
4545
};
4646

4747
class AwsLambda extends Component {

packages/serverless-components/aws-lambda/utils.js

Lines changed: 18 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -158,28 +158,30 @@ const updateLambdaConfig = async ({
158158
.updateFunctionConfiguration(functionConfigParams)
159159
.promise();
160160

161-
// Get and update Lambda tags
162-
const listTagsResponse = await lambda
163-
.listTags({ Resource: res.FunctionArn })
164-
.promise();
165-
const currentTags = listTagsResponse.Tags;
166-
167-
// If tags are not the same then update them
168-
if (!_.isEqual(currentTags, tags)) {
169-
await lambda
170-
.untagResource({
171-
Resource: res.FunctionArn,
172-
Tags: Object.keys(currentTags)
173-
})
161+
// Get and update Lambda tags only if tags are specified (for backwards compatibility and avoiding unneeded updates)
162+
if (tags) {
163+
const listTagsResponse = await lambda
164+
.listTags({ Resource: res.FunctionArn })
174165
.promise();
166+
const currentTags = listTagsResponse.Tags;
175167

176-
if (tags && Object.keys(tags).length > 0)
168+
// If tags are not the same then update them
169+
if (!_.isEqual(currentTags, tags)) {
177170
await lambda
178-
.tagResource({
171+
.untagResource({
179172
Resource: res.FunctionArn,
180-
Tags: tags
173+
Tags: Object.keys(currentTags)
181174
})
182175
.promise();
176+
177+
if (Object.keys(tags).length > 0)
178+
await lambda
179+
.tagResource({
180+
Resource: res.FunctionArn,
181+
Tags: tags
182+
})
183+
.promise();
184+
}
183185
}
184186

185187
return { arn: res.FunctionArn, hash: res.CodeSha256 };

packages/serverless-components/nextjs-component/src/component.ts

Lines changed: 8 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -572,10 +572,11 @@ class NextjsComponent extends Component {
572572
"nodejs12.x"
573573
) as string,
574574
name: bucketOutputs.name,
575-
tags: readLambdaInputValue("tags", "regenerationLambda", {}) as Record<
576-
string,
577-
string
578-
>
575+
tags: readLambdaInputValue(
576+
"tags",
577+
"regenerationLambda",
578+
undefined
579+
) as Record<string, string>
579580
};
580581

581582
const regenerationLambdaResult = await regenerationLambda(
@@ -615,7 +616,7 @@ class NextjsComponent extends Component {
615616
name: readLambdaInputValue("name", "apiLambda", undefined) as
616617
| string
617618
| undefined,
618-
tags: readLambdaInputValue("tags", "apiLambda", {}) as Record<
619+
tags: readLambdaInputValue("tags", "apiLambda", undefined) as Record<
619620
string,
620621
string
621622
>
@@ -676,7 +677,7 @@ class NextjsComponent extends Component {
676677
name: readLambdaInputValue("name", "imageLambda", undefined) as
677678
| string
678679
| undefined,
679-
tags: readLambdaInputValue("tags", "imageLambda", {}) as Record<
680+
tags: readLambdaInputValue("tags", "imageLambda", undefined) as Record<
680681
string,
681682
string
682683
>
@@ -741,7 +742,7 @@ class NextjsComponent extends Component {
741742
name: readLambdaInputValue("name", "defaultLambda", undefined) as
742743
| string
743744
| undefined,
744-
tags: readLambdaInputValue("tags", "defaultLambda", {}) as Record<
745+
tags: readLambdaInputValue("tags", "defaultLambda", undefined) as Record<
745746
string,
746747
string
747748
>

0 commit comments

Comments
 (0)