This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
exports.handler = async (event, context, callback) => { | |
const request = event.Records[0].cf.request; | |
const headers = request.headers; | |
const user = 'YOUR_USERNAME_HERE'; | |
const pass = 'YOUR_PASSWORD_HERE'; | |
const basicAuthentication = 'Basic ' + new Buffer(user + ':' + pass).toString('base64'); |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
{ | |
"Version": "2012-10-17", | |
"Statement": [ | |
{ | |
"Sid": "RegionRestriction", | |
"Effect": "Deny", | |
"NotAction": [ | |
"apigateway:*", | |
"amplify:*", | |
"amplifybackend:*", |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// First we create forecast dataset with datafrequency of 1 | |
// We use a timeseries AutoML, the target column is costs | |
const forecastDataset = new AwsCustomResource(this, `forecastDataset`, { | |
onUpdate: { | |
service: 'ForecastService', | |
action: 'createDataset', | |
parameters: { | |
Domain: 'CUSTOM', | |
DatasetName: 'amazonForecastDataset', | |
DataFrequency: 'D', |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// We create the dataset which reads the parquet files in the 2021 bucket prefix | |
const cfnDataset = new CfnDataset(this, 'Dataset', { | |
name: 'cost-and-usage-report-dataset', | |
input: { | |
s3InputDefinition: { | |
bucket: `cost-and-usage-report-dataset-2021-12-12`, | |
key: `2021/<[^/]+>.parquet`, | |
}, | |
}, | |
format: 'PARQUET', |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// Creation of databrew role used by forecast and databrew | |
const dataBrewRole = new Role(this, 'costAndUsageReportRole', { | |
roleName: 'dataBrewServiceRole', | |
assumedBy: new CompositePrincipal( | |
new ServicePrincipal('databrew.amazonaws.com'), | |
new ServicePrincipal('forecast.amazonaws.com'), | |
), | |
path: '/service-role/', | |
}); |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
const loadUrl = async function(page, url, takeScreenshot) { | |
let stepName = null; | |
let domcontentloaded = false; | |
try { | |
stepName = new URL(url).hostname; | |
} catch (error) { | |
const errorString = `Error parsing url: ${url}. ${error}`; | |
log.error(errorString); | |
/* If we fail to parse the URL, don't emit a metric with a stepName based on it. |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
async function login(email, password) { | |
try { | |
const cognito = new AWS.CognitoIdentityServiceProvider(); | |
return await cognito.initiateAuth({ | |
AuthFlow: 'USER_PASSWORD_AUTH', | |
ClientId: 'XXXXXXXXXXXXXXXXXXX', | |
AuthParameters: { | |
USERNAME: email, | |
PASSWORD: password, | |
}, |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
const loadBlueprint = async function() { | |
const response = login(USERNAME, PASSWORD); | |
const bearerToken = (await response).AuthenticationResult.IdToken; | |
const urls = ['https://probkotestov.io/api-users/setting']; | |
// Set screenshot option | |
const takeScreenshot = true; | |
/* Disabling default step screen shots taken during Synthetics.executeStep() calls | |
* Step will be used to publish metrics on time taken to load dom content but |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
const { URL } = require('url'); | |
const synthetics = require('Synthetics'); | |
const log = require('SyntheticsLogger'); | |
const syntheticsConfiguration = synthetics.getConfiguration(); | |
const syntheticsLogHelper = require('SyntheticsLogHelper'); | |
const AWS = require('aws-sdk'); | |
AWS.config.update({ | |
region: 'eu-central-1', | |
}); | |
//Username and password should be passed by using Secrets Manager get secret value api call. |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import { Construct, Duration, Stack } from '@aws-cdk/core'; | |
import { Bucket, BucketEncryption } from '@aws-cdk/aws-s3'; | |
import { Code, Function, IFunction, Runtime } from '@aws-cdk/aws-lambda'; | |
import * as path from 'path'; | |
import { Effect, PolicyStatement } from '@aws-cdk/aws-iam'; | |
export interface CognitoUserMigrationLambdaProps { | |
readonly userPoolId: string; | |
readonly bucketName: string; |