2022-09-19 12:00:09 -04:00
// Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved.
// SPDX-License-Identifier: Apache-2.0
import {
LambdaClient ,
UpdateFunctionConfigurationCommand ,
2024-11-18 10:54:42 -07:00
waitUntilFunctionUpdated ,
2022-09-19 12:00:09 -04:00
} from "@aws-sdk/client-lambda" ;
2024-10-16 11:53:18 -04:00
import { readFileSync } from "node:fs" ;
2024-02-22 10:32:44 -05:00
import { dirnameFromMetaUrl } from "@aws-doc-sdk-examples/lib/utils/util-fs.js" ;
2024-11-18 10:54:42 -07:00
import { waitForFunctionUpdated } from "../waiters/index.js" ;
2022-09-19 12:00:09 -04:00
const dirname = dirnameFromMetaUrl ( import . meta . url ) ;
2022-09-19 14:05:31 -04:00
/** snippet-start:[javascript.v3.lambda.actions.UpdateFunctionConfiguration] */
2023-04-07 14:07:21 -04:00
const updateFunctionConfiguration = ( funcName ) => {
const client = new LambdaClient ( { } ) ;
const config = readFileSync ( ` ${ dirname } ../functions/config.json ` ) . toString ( ) ;
2022-09-19 12:00:09 -04:00
const command = new UpdateFunctionConfigurationCommand ( {
... JSON . parse ( config ) ,
FunctionName : funcName ,
} ) ;
2024-11-18 10:54:42 -07:00
const result = client . send ( command ) ;
waitForFunctionUpdated ( { FunctionName : funcName } ) ;
return result ;
2022-09-19 12:00:09 -04:00
} ;
2022-09-19 14:05:31 -04:00
/** snippet-end:[javascript.v3.lambda.actions.UpdateFunctionConfiguration] */
2022-09-19 12:00:09 -04:00
export { updateFunctionConfiguration } ;