{"action":"created","issue":{"url":"https://api.github.com/repos/awslabs/aws-cdk/issues/716","repository_url":"https://api.github.com/repos/awslabs/aws-cdk","labels_url":"https://api.github.com/repos/awslabs/aws-cdk/issues/716/labels{/name}","comments_url":"https://api.github.com/repos/awslabs/aws-cdk/issues/716/comments","events_url":"https://api.github.com/repos/awslabs/aws-cdk/issues/716/events","html_url":"https://github.com/awslabs/aws-cdk/issues/716","id":360485656,"node_id":"MDU6SXNzdWUzNjA0ODU2NTY=","number":716,"title":"Example: AWS SAM","user":{"login":"0xdevalias","id":753891,"node_id":"MDQ6VXNlcjc1Mzg5MQ==","avatar_url":"https://avatars1.githubusercontent.com/u/753891?v=4","gravatar_id":"","url":"https://api.github.com/users/0xdevalias","html_url":"https://github.com/0xdevalias","followers_url":"https://api.github.com/users/0xdevalias/followers","following_url":"https://api.github.com/users/0xdevalias/following{/other_user}","gists_url":"https://api.github.com/users/0xdevalias/gists{/gist_id}","starred_url":"https://api.github.com/users/0xdevalias/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/0xdevalias/subscriptions","organizations_url":"https://api.github.com/users/0xdevalias/orgs","repos_url":"https://api.github.com/users/0xdevalias/repos","events_url":"https://api.github.com/users/0xdevalias/events{/privacy}","received_events_url":"https://api.github.com/users/0xdevalias/received_events","type":"User","site_admin":false},"labels":[{"id":971559088,"node_id":"MDU6TGFiZWw5NzE1NTkwODg=","url":"https://api.github.com/repos/awslabs/aws-cdk/labels/documentation","name":"documentation","color":"fbca04","default":true},{"id":1110651955,"node_id":"MDU6TGFiZWwxMTEwNjUxOTU1","url":"https://api.github.com/repos/awslabs/aws-cdk/labels/feature-request","name":"feature-request","color":"008672","default":false}],"state":"open","locked":false,"assignee":null,"assignees":[],"milestone":null,"comments":21,"created_at":"2018-09-14T23:48:55Z","updated_at":"2019-06-26T21:33:40Z","closed_at":null,"author_association":"NONE","body":"I think it could be useful to have a basic canonical example of how to use [SAM](https://github.com/awslabs/aws-sam-cli) from CDK (See also: #703, https://github.com/awslabs/aws-sam-cli/issues/663)\r\n\r\nIf it would be useful, I could probably knock together what I figured out here into a PR to examples? If so.. what would be the best naming/etc for it? Potentially could choose one of the simpler examples from the following and translate it to CDK:\r\n\r\n* https://github.com/awslabs/serverless-application-model/tree/master/examples\r\n\r\nI found the following, so should be doable:\r\n* https://github.com/awslabs/aws-cdk/tree/master/packages/%40aws-cdk/aws-sam\r\n\r\nBut when I was exploring the docs, it didn't look like I could do much without dropping into the `cloudformation` namespace (which is probably fine, as this is 'lower level/direct mapping'):\r\n\r\n* https://awslabs.github.io/aws-cdk/refs/_aws-cdk_aws-sam.html\r\n\r\nSo I decided to try and make a basic function example from that, just to see how it would work. It took me a little while to figure the intricacies of the types used and their interrelations:\r\n\r\n```typescript\r\nimport sam = require('@aws-cdk/aws-serverless');\r\n```\r\n```typescript\r\nconst helloWorld = new sam.cloudformation.FunctionResource(this, \"HelloWorld\", {\r\n            functionName: \"HelloWorld\",\r\n            description: \"Greeting the world\",\r\n            codeUri: \"./target\",\r\n            handler: \"hello-world\",\r\n            runtime: lambda.Runtime.Go1x.name,\r\n            tracing: \"active\",\r\n            events: {\r\n                CatchAll: {\r\n                    type: \"Api\",\r\n                    properties: {\r\n                        path: \"/{proxy+}\",\r\n                        method: \"ANY\",\r\n                        // restApiId: \"\"\r\n                    }\r\n                }\r\n            }\r\n        });\r\n```\r\n\r\nWhich synthesises to:\r\n\r\n```yaml\r\nTransform: 'AWS::Serverless-2016-10-31'\r\nResources:\r\n    HelloWorld:\r\n        Type: 'AWS::Serverless::Function'\r\n        Properties:\r\n            CodeUri: ./target\r\n            Handler: hello-world\r\n            Runtime: go1.x\r\n            Description: 'Greeting the world'\r\n            Events:\r\n                CatchAll:\r\n                    Properties:\r\n                        Method: ANY\r\n                        Path: '/{proxy+}'\r\n                    Type: Api\r\n            FunctionName: HelloWorld\r\n            Tracing: active\r\n    CDKMetadata:\r\n        Type: 'AWS::CDK::Metadata'\r\n        Properties:\r\n            Modules: '@aws-cdk/assets=0.9.0,@aws-cdk/aws-cloudwatch=0.9.0,@aws-cdk/aws-codepipeline-api=0.9.0,@aws-cdk/aws-ec2=0.9.0,@aws-cdk/aws-elasticloadbalancing=0.9.0,@aws-cdk/aws-events=0.9.0,@aws-cdk/aws-iam=0.9.0,@aws-cdk/aws-kms=0.9.0,@aws-cdk/aws-lambda=0.9.0,@aws-cdk/aws-s3=0.9.0,@aws-cdk/aws-s3-notifications=0.9.0,@aws-cdk/aws-serverless=0.9.0,@aws-cdk/aws-sqs=0.9.0,@aws-cdk/cdk=0.9.0,@aws-cdk/cx-api=0.9.0,js-base64=2.4.5,poc-aws-cdk=0.1.0'\r\n```\r\n\r\n**CDK References:**\r\n\r\n* https://awslabs.github.io/aws-cdk/refs/_aws-cdk_aws-sam.html#functionresource\r\n* https://awslabs.github.io/aws-cdk/refs/_aws-cdk_aws-sam.html#functionresourceprops-interface\r\n* https://awslabs.github.io/aws-cdk/refs/_aws-cdk_aws-sam.html#@aws-cdk/aws-sam.cloudformation.FunctionResource.ApiEventProperty\r\n\r\n**SAM References:**\r\n\r\n* https://github.com/awslabs/serverless-application-model/blob/master/versions/2016-10-31.md#awsserverlessfunction\r\n* https://github.com/awslabs/serverless-application-model/blob/master/versions/2016-10-31.md#event-source-types\r\n* https://github.com/awslabs/serverless-application-model/blob/master/versions/2016-10-31.md#event-source-object\r\n* https://github.com/awslabs/serverless-application-model/blob/master/versions/2016-10-31.md#api"},"comment":{"url":"https://api.github.com/repos/awslabs/aws-cdk/issues/comments/506053772","html_url":"https://github.com/awslabs/aws-cdk/issues/716#issuecomment-506053772","issue_url":"https://api.github.com/repos/awslabs/aws-cdk/issues/716","id":506053772,"node_id":"MDEyOklzc3VlQ29tbWVudDUwNjA1Mzc3Mg==","user":{"login":"jfuss","id":32497805,"node_id":"MDQ6VXNlcjMyNDk3ODA1","avatar_url":"https://avatars2.githubusercontent.com/u/32497805?v=4","gravatar_id":"","url":"https://api.github.com/users/jfuss","html_url":"https://github.com/jfuss","followers_url":"https://api.github.com/users/jfuss/followers","following_url":"https://api.github.com/users/jfuss/following{/other_user}","gists_url":"https://api.github.com/users/jfuss/gists{/gist_id}","starred_url":"https://api.github.com/users/jfuss/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/jfuss/subscriptions","organizations_url":"https://api.github.com/users/jfuss/orgs","repos_url":"https://api.github.com/users/jfuss/repos","events_url":"https://api.github.com/users/jfuss/events{/privacy}","received_events_url":"https://api.github.com/users/jfuss/received_events","type":"User","site_admin":false},"created_at":"2019-06-26T21:33:40Z","updated_at":"2019-06-26T21:33:40Z","author_association":"CONTRIBUTOR","body":"@cpmech CDK currently only supports generating the raw API Gateway resources. So the two paths to the support would be:\r\n\r\n1. CDK generates Swagger instead of resources for customers\r\n2. SAM CLI support the raw API Gateway Resources.\r\n\r\nI know there is an issue for the first, but I wouldn't expect this to cover all customers, given the current state.\r\n\r\nOn the second, we are currently under going some work on support API Gateway Resources. [Design PR](https://github.com/awslabs/aws-sam-cli/pull/1234). We plan on supporting RestApi with swagger to start, while we try to understand the full need for support the wider API Gateway Resources (such as `AWS::ApiGateway::Method`)."}}
{"actor":{"display_login":"jfuss"}}