Sceptre: Docs request for Serverless SAM

Created on 8 Dec 2019  路  10Comments  路  Source: Sceptre/sceptre

I can see some basic support in Sceptre for AWS SAM although there don't appear to be any code examples or blog posts and it's unclear to me how you would actually do SAM in Sceptre, especially after SAM's guided deploy mode became the standard.

In the mean time, can anyone suggest the high level approach- would I create a Python wrapper to call the SAM CLI to do sam build and sam package and then use the output of sam package as the Sceptre template?

docs

Most helpful comment

I agree that SAM is an important piece of modern AWS infrastructure and that sceptre docs would be enhanced by including SAM guidance.

I stared with a sceptre hook based, but found it ugly to implement both before_create and before_update with cut and paste.

We followed the SAM CLI solution path and:

  • had a pre-step to sceptre launch the required artifact bucket
  • pulled the name of the bucket with sceptre list output
  • passed that name via environment variable to a step that did a smart sam build and sam package writing artifacts to the bucket and outputting a (.gitignore-d) CFN to the template/ folder
  • this generated CFN was then available for use in subsequent sceptre launchs

I can create a sample repo, or contribute to the docs, if this pattern is of interest.

All 10 comments

thanks for the info @alexharv074 The way to pass in S3 bucket to your sceptre_handler is to do something like this..

in templates/mytemplate.yaml

template_path: mytemplate.py
stack_name: mystack
sceptre_user_data:
  my_bucket: "alexharvey3118"

You should have access to sceptre_user_data.my_bucket in your sceptre_handler() method.

You could, alternatively, provide the same functionality with a sceptre hook. The hook would process the handler and trophosphere code before deploying to AWS.

Another alternative is to just use the SAM CLI to build and deploy process the SAM templates to an S3 bucket then have sceptre take over with deploying the generated SAM template to AWS. This is what we do using our CI, https://github.com/Sage-Bionetworks/aws-infra/blob/master/.travis.yml

I agree that SAM is an important piece of modern AWS infrastructure and that sceptre docs would be enhanced by including SAM guidance.

I stared with a sceptre hook based, but found it ugly to implement both before_create and before_update with cut and paste.

We followed the SAM CLI solution path and:

  • had a pre-step to sceptre launch the required artifact bucket
  • pulled the name of the bucket with sceptre list output
  • passed that name via environment variable to a step that did a smart sam build and sam package writing artifacts to the bucket and outputting a (.gitignore-d) CFN to the template/ folder
  • this generated CFN was then available for use in subsequent sceptre launchs

I can create a sample repo, or contribute to the docs, if this pattern is of interest.

That would be awesome sounds like a good approach

I've published:
https://github.com/Versent/sam-sceptre

This repo gives a example skeleton for deploying AWS Lambda resources in CloudFormation templates or SAM templates using CloudReach's Sceptre.

Feedback welcome.

if this helps anyone, we too have a github template for creating a sam app and deploying with sceptre. https://github.com/Sage-Bionetworks-IT/lambda-template

It would be cool to include these in the main docs - at least a link to the external examples or even bring these examples into the main docs. What do you think @jghaines & @zaro0508 ?

Seems like a good idea @ngfgrant however i'm not sure what you are expecting. Did you want a PR to update the docs with your suggestions?

If you'd or jghaines would be willing to then it would be an easily accepted PR for sure!

Was this page helpful?
0 / 5 - 0 ratings

Related issues

sathed picture sathed  路  3Comments

medbensalem picture medbensalem  路  7Comments

dalibor-aleksic-atomia picture dalibor-aleksic-atomia  路  4Comments

brian-provenzano picture brian-provenzano  路  6Comments

cyphus picture cyphus  路  4Comments