Yandex Cloud
Search
Contact UsGet started
  • Blog
  • Pricing
  • Documentation
  • All Services
  • System Status
    • Featured
    • Infrastructure & Network
    • Data Platform
    • Containers
    • Developer tools
    • Serverless
    • Security
    • Monitoring & Resources
    • ML & AI
    • Business tools
  • All Solutions
    • By industry
    • By use case
    • Economics and Pricing
    • Security
    • Technical Support
    • Customer Stories
    • Gateway to Russia
    • Cloud for Startups
    • Education and Science
  • Blog
  • Pricing
  • Documentation
Yandex project
© 2025 Yandex.Cloud LLC
Yandex Serverless Containers
  • Comparison with other Yandex Cloud services
    • All guides
    • Getting an IAM token for a service account using a container
    • Viewing operations with service resources
  • Access management
  • Pricing policy
  • Terraform reference
  • Audit Trails events
  • Release notes
  • FAQ
  1. Step-by-step guides
  2. Getting an IAM token for a service account using a container

Getting an IAM token for a service account using a container

Written by
Yandex Cloud
Updated at March 7, 2025

If the container revision was created with a service account, you can get an IAM token from the metadata service in Google Compute Engine using the API.

To do this, from inside the container, send a GET request to http://169.254.169.254/computeMetadata/v1/instance/service-accounts/default/token and specify the Metadata-Flavor: Google HTTP header.

Below is an example of a function for obtaining an IAM token.

JavaScript
const fetch = require("node-fetch");
let url = 'http://169.254.169.254/computeMetadata/v1/instance/service-accounts/default/token';
let headers = {'Metadata-Flavor': 'Google'};

async function getToken(event) {
    const resp = await fetch(url, {
        headers: headers,
    });
    let respJson = await resp.json();
    return {
        token: respJson['access_token'],
        expiresInSeconds: respJson['expires_in'],
    };
};

Was the article helpful?

Previous
All guides
Next
Getting a list of containers
Yandex project
© 2025 Yandex.Cloud LLC