Add a custom AWS resource (not normally supported by CF) during deploy?

I want to build a service that uses elastic transcoder. While I could build the transcoder pipeline and presets ahead of time, I would prefer to have that work done in ‘serverless deploy’

Let’s say I wanted to create a transcoder pipeline and presets for use in a lambda function, so therefore I need the lambda to know the name and ARN of the pipeline and ids for the presets.

How would I go about making sure that the pipeline and presets get created and removed at the right times and how do I pass the needed information to the lambda and possibly to the CF outputs for the stack?

You can use a lambda backed custom resource to spin up whatever you want and then return values back to reference in other parts of your yaml

https://docs.aws.amazon.com/AWSCloudFormation/latest/UserGuide/template-custom-resources.html

In the response from your lambda backed custom resource you can return values back in Data and then (beforehand) reference that with cloudformation getAttr

{
   "Status" : "SUCCESS",
   "PhysicalResourceId" : "TestResource1",
   "StackId" : "arn:aws:cloudformation:us-west-2:EXAMPLE:stack/stack-name/guid",
   "RequestId" : "unique id for this create request",
   "LogicalResourceId" : "MyTestResource",
   "Data" : {
      "OutputName1" : "Value1",
      "OutputName2" : "Value2",
   }
}

This is a good post on the topic https://stelligent.com/2016/02/16/aws-lambda-backed-custom-resources-for-stack-outputs-resources-and-parameters/

1 Like

Thanks! I had found that stuff, but I wonder: can this be incorporated into a serverless.yml service?

If raw cloudformation supports the functionality yes.

Otherwise you will need to:

  1. write the custom resource and use it
  2. or script the outcome and make it a serverless plugin running on pre/post-deploy hooks

@eliasisrael
Custom Resources are the way to go for things not natively supported in CFN.

Especially if it IS however supported by the AWS SDK.

For your specific example of transcoder resources. I’m actually refactoring these to deploy with SLS.

They both work great out of the box, but the UPDATE ignores OutputBucket changes which was an issue for us. I have a fix for that too.
I’ll be open sourcing the fork once I’m done which hopefully will be before EOW.

Thanks! We found those too, and based our work on those examples.

Here are those that I’ve refactored to SLS and fixed some update pipeline bugs that were in them.

Cheers,
D

2 Likes