Lambda code

An AWS Lambda function code that uses axios to send API requests to GitHub traffic API to get daily views on a GitHub repository. The function uses SSM parameter store to retrieve GitHub Personal Access Token.
 avatar
unknown
javascript
2 years ago
860 B
41
Indexable
const axios = require('axios');
const AWS = require('aws-sdk');

const ssm = new AWS.SSM();

exports.handler = async (event) => {
    // Get GitHub Personal Access Token from SSM Parameter Store
    const ssmParams = {
        Name: '/github/access_token',
        WithDecryption: true
    };
    const accessToken = (await ssm.getParameter(ssmParams).promise()).Parameter.Value;
    // Configure axios
    const axiosConfig = {
        headers: {
            'Authorization': `Token ${accessToken}`
        }
    };
    // Send API request to GitHub Traffic API
    const repository = 'OWNER/REPO';
    const url = `https://api.github.com/repos/${repository}/traffic/views`;
    const response = await axios.get(url, axiosConfig);
    const dailyViews = response.data.views;
    // Return daily views
    return { dailyViews };
};

Editor is loading...