Configuring metadata service parameters for a function
You can configure metadata service parameters when creating a function version.
Available options:
-
awsV1HttpEndpoint
: Provides access to metadata using the AWS format (IMDSv1). It can be eitherenabled
ordisabled
. If set todisabled
, the metadata request will fail with error404 Not Found
. The default value isenabled
.Note
The
awsV1HttpEndpoint
parameter isenabled
by 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 eitherenabled
ordisabled
. If set todisabled
, the metadata request will fail with error404 Not Found
. The default value isenabled
.
- In the management console
, select the folder containing the function. - Select Cloud Functions.
- Select a function.
- Navigate to the Editor tab.
- Expand the Additional settings section.
- Under Metadata service parameters, configure the parameters of the function metadata service:
Access metadata using the Google Compute Engine format
andAccess 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_environment> \
--entrypoint <entry_point> \
--source-version-id <version_ID> \
--metadata-options <option>=<enabled_or_disabled>
Where:
--function-id
: ID of the function a new version of which you want to create. To find out the function ID, get a list of functions in the folder.--runtime
: Runtime environment.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 a 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 documentation on the Terraform
If you don't have Terraform, 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_options
section to the function description:resource "yandex_function" "metadata_function" { name = "<function_name>" user_hash = "<function_hash>" runtime = "<runtime_environment>" entrypoint = "<entry_point>" memory = "<RAM_size>" 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:0
if you want to keep the default value.1
to enable the parameter.2
to disable the parameter.
For more information about the
yandex_function
resource parameters, see this Terraform article . -
Apply the changes:
-
In the terminal, change to the folder where you edited the configuration file.
-
Make sure the configuration file is correct using the command:
terraform validate
If the configuration is correct, the following message is returned:
Success! The configuration is valid.
-
Run the command:
terraform plan
The terminal will display a list of resources with parameters. No changes are made at this step. If the configuration contains errors, Terraform will point them out.
-
Apply the configuration changes:
terraform apply
-
Confirm the changes: type
yes
in the terminal and press Enter.
-
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.