Configuring metadata service parameters for a function
You can configure metadata service parameters when creating a function version.
The following options are available:
-
awsV1HttpEndpoint: Provides access to metadata using the AWS format (IMDSv1). It can be eitherenabledordisabled. If set todisabled, the metadata request will fail with the404 Not Founderror. The default value isenabled.Note
awsV1HttpEndpointisenabledby default, but we recommend disabling it. The IMDSv1 format comes with a number of security vulnerabilities. Its most severe flaw is the high risk of attacks, such as SSRF . For more information, see the AWS official blog . -
gceHttpEndpoint: Provides access to metadata using the Google Compute Engine format. It can be eitherenabledordisabled. If set todisabled, the metadata request will fail with the404 Not Founderror. The default value isenabled.
- In the management console
, navigate to the folder containing the function. - Go to Cloud Functions.
- Select the function.
- Navigate to the Editor tab.
- Expand Additional settings.
- Under Metadata service parameters, configure the parameters of the function metadata service:
Access metadata using the Google Compute Engine formatandAccess metadata using the AWS format (IMDSv1). - Click Save changes.
To configure metadata service parameters for a function, run this command:
yc serverless function version create \
--function-id=<function_ID> \
--runtime <runtime> \
--entrypoint <entry_point> \
--source-version-id <version_ID> \
--metadata-options <option>=<enabled_or_disabled>
Where:
--function-id: ID of the function whose new version you want to create. To find out the function ID, get the list of functions in the folder.--runtime: Runtime.--entrypoint: Entry point in<function_file_name>.<handler_name>format.--source-version-id: ID of the function version from which you want to copy the code. To find out the ID, get the list of function versions.--metadata-options: Settings for the metadata service parameters, e.g.,aws-v1-http-endpoint=disabled.
With Terraform
Terraform is distributed under the Business Source License
For more information about the provider resources, see the relevant documentation on the Terraform
If you do not have Terraform yet, install it and configure the Yandex Cloud provider.
To configure metadata service parameters for a function:
-
Open the Terraform configuration file and add the
metadata_optionssection to the function description:resource "yandex_function" "metadata_function" { name = "<function_name>" user_hash = "<function_hash>" runtime = "<runtime>" entrypoint = "<entry_point>" memory = "<RAM_amount>" execution_timeout = "<execution_timeout>" service_account_id = "<service_account_ID>" content { zip_filename = "<path_to_ZIP_archive>" } metadata_options { metadata_options.0.gce_http_endpoint = "0_or_1_or_2" metadata_options.0.aws_v1_http_endpoint = "0_or_1_or_2" } }Where:
metadata_options: Settings for the metadata service parameters, e.g.,metadata_options.0.gce_http_endpoint = "1". Specify the following:0if you want to keep the default value.1to enable the parameter.2to disable the parameter.
For more information about
yandex_functionresource properties, see this provider guide. -
Apply the changes:
-
In the terminal, navigate to the configuration file directory.
-
Make sure the configuration is correct using this command:
terraform validateIf the configuration is valid, you will get this message:
Success! The configuration is valid. -
Run this command:
terraform planYou will see a list of resources and their properties. No changes will be made at this step. Terraform will show any errors in the configuration.
-
Apply the configuration changes:
terraform apply -
Type
yesand press Enter to confirm the changes.
-
You can check the function update and its new configuration using the management console
yc serverless function version get <function_version_ID>
To create a function version, use the createVersion REST API method for the Function resource or the FunctionService/CreateVersion gRPC API call.