Skip to content

Instantly share code, notes, and snippets.

What would you like to do?
const cuid = require('cuid')
const AWS = require('aws-sdk')
const REGION = 'us-east-1'
const SNS_ARN = process.env.SNS_ARN
const TEMPLATE_URL = process.env.TEMPLATE_URL
var SNS = new AWS.SNS();
function generateStackUrl(userExternalId) {
const baseUrl = new URL('')
baseUrl.searchParams.append('region', REGION)
baseUrl.hash = ('/stacks/create/review')
const searchParams = new URLSearchParams()
searchParams.append('stackName', 'CoolCompany-Role')
searchParams.append('templateURL', TEMPLATE_URL)
searchParams.append('param_ExternalId', userExternalId)
searchParams.append('param_TrustedAccount', TRUSTED_ACCOUNT)
searchParams.append('param_SnsArn', SNS_ARN)
return `${baseUrl.href}?${searchParams}`
module.exports.handler = async (event, context) => {
console.log("Generating user template")
const userAccountId = event.queryStringParameters.userAccountId
const externalId = cuid()
let generatedUrl = generateStackUrl(externalId)
console.log(`Generated Url: ${generatedUrl}`)
return {
statusCode: 200,
requestUrl: generatedUrl
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment