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...