This is a audio-processing project for CDK development with TypeScript.
The cdk.json file tells the CDK Toolkit how to execute your app.
npm run buildcompile typescript to jsnpm run watchwatch for changes and compilenpx cdk deploydeploy this stack to your default AWS account/regionnpx cdk destroydelete this stack with all the resources it includesnpx cdk diffcompare deployed stack with current statenpx cdk synthemits the synthesized CloudFormation template
const res = await fetch('https://n2klthh2tl.execute-api.us-east-1.amazonaws.com/prod/transcode', {
method: 'POST',
body: JSON.stringify({
url: "https://pub-951fa3482dca41f6bf9fa25a7953175d.r2.dev/ytaudio.webm",
requestId: "XXXXXXXXXXXXXXXX" //optional
}),
headers: {
'Content-Type': 'application/json'
}
})
const data = await res.json()
console.log(data)
// {
// success: true,
// requestId: 'XXXXXXXXXXXXXXXX',
// url: 'https://audioprocessingstack-s3100bedfb-ihhtoldoybzj.s3.us-east-1.amazonaws.com/ffmpeg/temp/3f4775f7dfdada3f/f4775f7dfdada3f8.ogg'
// } const res = await fetch('https://n2klthh2tl.execute-api.us-east-1.amazonaws.com/prod/concat', {
method: 'POST',
body: JSON.stringify({
urls: ["https://pub-951fa3482dca41f6bf9fa25a7953175d.r2.dev/ytaudio.webm", "https://pub-951fa3482dca41f6bf9fa25a7953175d.r2.dev/ytaudio.webm"],
requestId: "XXXXXXXXXXXXXXXX" //optional
}),
headers: {
'Content-Type': 'application/json'
}
})
const data = await res.json()
console.log(data)
// {
// success: true,
// requestId: 'XXXXXXXXXXXXXXXX',
// url: 'https://audioprocessingstack-s3100bedfb-ihhtoldoybzj.s3.us-east-1.amazonaws.com/ffmpeg/temp/3f4775f7dfdada3f/f4775f7dfdada3f8.ogg'
// }- Go to AWS Identity and Access Management (IAM)
- Create a new policie from JSON
{
"Version": "2012-10-17",
"Statement": [
{
"Effect": "Allow",
"Action": [
"sts:AssumeRole"
],
"Resource": [
"arn:aws:iam::*:role/cdk-*"
]
},
{
"Effect": "Allow",
"Action": [
"cloudformation:*"
],
"Resource": "*"
}
]
}- Save the policie by providing a name (eg: cdk-deploy).
- Create a user and as attatch permissions policie that you just created frow AWS console.
- Select the newly created user and go to the
Security credentialstab. - Now on the
Access keyssection, click on theCreate access keybutton. - Now select use case
Command Line Interface (CLI)and confirm. Click on the next button. - Click
Create access keybutton. - Now store the
Access keyandSecret access key.
- Go to github repo settings.
- On the
Securitysection click onSecrets and variableand then click onaction. - Now click on
New repository secretand two secretAWS_ACCESS_KEY_IDandAWS_SECRET_KEYand the value should be theAccess keyandSecret access keyyou got from AWS console. - (Optional) Set another secret
AWS_REGIONto specify the deployment region. Default region isus-east-1.
- You can triger deployment manually by going to
Actiontab on github repo. - The choosing
CDK Deployaction and clicking onRun workflowbutton.
If you set up github action then whenever a new code push happen on master branch, the deployment will update automatically.
You can find the deployment url inside github action log. Here is a sample output:
✅ AudioProcessingStack
✨ Deployment time: 42.59s
Outputs:
AudioProcessingStack.gatewayEndpointDA8D204E = https://fivtqcifhd.execute-api.us-east-1.amazonaws.com/prod/
Stack ARN:
arn:aws:cloudformation:us-east-1:***:stack/AudioProcessingStack/b4cff7e0-6df8-11ef-b5ff-0ee5f6741be1
✨ Total time: 47.23s
You can see here there is a url https://fivtqcifhd.execute-api.us-east-1.amazonaws.com/prod/ inside log output. This is the lambda api gatway URL.
You can invoke lambda using this URL.
If you want to add a custom domain you can follow this guide: https://medium.com/geekculture/how-to-add-a-custom-domain-to-lambda-functions-1bc0ae639676
You can change lambda RAM size and timeout setting inside this file: lib/audio-processing-stack.ts
These are the currentl values:
memorySize: 3008
timeout: cdk.Duration.seconds(300)