Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

(SAM): update the SAM specification version used in the CDK #13507

Closed
skinny85 opened this issue Mar 9, 2021 · 9 comments
Closed

(SAM): update the SAM specification version used in the CDK #13507

skinny85 opened this issue Mar 9, 2021 · 9 comments
Labels
@aws-cdk/aws-sam Related to AWS Serverless Application Model closed-for-staleness This issue was automatically closed because it hadn't received any attention in a while. effort/medium Medium work item – several days of effort feature/coverage-gap Gaps in CloudFormation coverage by L2 constructs feature-request A feature should be added or improved. p2

Comments

@skinny85
Copy link
Contributor

skinny85 commented Mar 9, 2021

We need to update the version of the SAM spec we use in the CDK. We are missing new properties, like PackageType in AWS::Serverless::Function, and some properties that we mark as required (like CodeUri of AWS::Serverless::Function) are no longer required.


(Additional data from related issues)

We currently download the spec from a repo called awslabs/goformation -

"https://raw.githubusercontent.com/awslabs/goformation/master/generate/sam-2016-10-31.json" \

Unfortunately, it seems that there is no machine readable SAM spec available officially - aws/serverless-application-model#1133. We need a better way to keep the SAM spec up to date with the latest, but without any machine-readable spec, this becomes a fairly difficult problem to stay on top of.

In the meantime, raw property overrides allow users to use missing properties, and missing resources can be created using CfnResource.
Neither of these are ideal, and we apologize for the current poor experience here.

@skinny85 skinny85 added feature-request A feature should be added or improved. needs-triage This issue or PR still needs to be triaged. labels Mar 9, 2021
@github-actions github-actions bot added the @aws-cdk/aws-sam Related to AWS Serverless Application Model label Mar 9, 2021
@skinny85
Copy link
Contributor Author

skinny85 commented Mar 9, 2021

@dannyoboy
Copy link

Hi, I'm not sure if this is the right place to point this out, but it is relevant to the issue. The AWS::Serverless::Function property DeploymentPreference has a Hooks property that is specified as a list of strings in cdk. However, the cloud formation docs let you specify between pretraffic and posttraffic hooks: https://docs.aws.amazon.com/serverless-application-model/latest/developerguide/sam-property-function-hooks.html. Currently, I don't think there's a way to specify pretraffic vs posttraffic hooks for DeploymentPreference in cdk.

@github-actions
Copy link

This issue has not received any attention in 1 year. If you want to keep this issue open, please leave a comment below and auto-close will be canceled.

@github-actions github-actions bot added closing-soon This issue will automatically close in 4 days unless further comments are made. closed-for-staleness This issue was automatically closed because it hadn't received any attention in a while. and removed closing-soon This issue will automatically close in 4 days unless further comments are made. labels Oct 18, 2022
@siarhei-klimuts
Copy link

Can not migrate my SAM template to CDK.

My SAM template works great, CodeUri of my functions point to local directories.
When using CfnInclude with the template, cdk synth looks good, but during cdk deploy on step creating CloudFormation changeset deploy fails with error: "'CodeUri' is not a valid S3 Uri of the form 's3://bucket/key' with optional versionId query parameter"

@skinny85
Copy link
Contributor Author

Can you show what codeUri is in your template?

@siarhei-klimuts
Copy link

Sure

CodeUri: ./notifications

@skinny85
Copy link
Contributor Author

Right. So I think this works because the SAM CLI does the packaging for you. In the CDK, you need to turn that directory into an Asset. I show how to do that in this video: https://youtu.be/bTC8XV5aLTo?si=3fdUJ_T1_cgXzejL

@siarhei-klimuts
Copy link

Right. So I think this works because the SAM CLI does the packaging for you. In the CDK, you need to turn that directory into an Asset. I show how to do that in this video: https://youtu.be/bTC8XV5aLTo?si=3fdUJ_T1_cgXzejL

Thank you! This is exactly what I needed.

But I stuck with another issue related to migration:
CfnInclude had no issues parsing my functions with Metadata: BuildMethod: makefile
But when I try to deploy my CDK stack I see that my functions code have not been built as it configured in the Makefile
So it looks like cdk deploy ignores Makefile.

Is it intendent?
Should I build function code firs and then create Asset on a built code?

@skinny85
Copy link
Contributor Author

Right. So I think this works because the SAM CLI does the packaging for you. In the CDK, you need to turn that directory into an Asset. I show how to do that in this video: https://youtu.be/bTC8XV5aLTo?si=3fdUJ_T1_cgXzejL

Thank you! This is exactly what I needed.

But I stuck with another issue related to migration: CfnInclude had no issues parsing my functions with Metadata: BuildMethod: makefile But when I try to deploy my CDK stack I see that my functions code have not been built as it configured in the Makefile So it looks like cdk deploy ignores Makefile.

Is it intendent? Should I build function code firs and then create Asset on a built code?

Yes. CDK Assets don’t use the Metadata in any way (this is another SAM feature), so you need to build your Lambda code separately. There is a “build” key that you can set in your cdk.json file for this purpose.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
@aws-cdk/aws-sam Related to AWS Serverless Application Model closed-for-staleness This issue was automatically closed because it hadn't received any attention in a while. effort/medium Medium work item – several days of effort feature/coverage-gap Gaps in CloudFormation coverage by L2 constructs feature-request A feature should be added or improved. p2
Projects
None yet
Development

No branches or pull requests

5 participants