{"action":"opened","issue":{"url":"https://api.github.com/repos/awslabs/aws-sam-local/issues/292","repository_url":"https://api.github.com/repos/awslabs/aws-sam-local","labels_url":"https://api.github.com/repos/awslabs/aws-sam-local/issues/292/labels{/name}","comments_url":"https://api.github.com/repos/awslabs/aws-sam-local/issues/292/comments","events_url":"https://api.github.com/repos/awslabs/aws-sam-local/issues/292/events","html_url":"https://github.com/awslabs/aws-sam-local/issues/292","id":294378569,"number":292,"title":"AWS::Serverless::API StageName ignored, Event defaults to \"prod\"","user":{"login":"christianklotz","id":69443,"avatar_url":"https://avatars2.githubusercontent.com/u/69443?v=4","gravatar_id":"","url":"https://api.github.com/users/christianklotz","html_url":"https://github.com/christianklotz","followers_url":"https://api.github.com/users/christianklotz/followers","following_url":"https://api.github.com/users/christianklotz/following{/other_user}","gists_url":"https://api.github.com/users/christianklotz/gists{/gist_id}","starred_url":"https://api.github.com/users/christianklotz/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/christianklotz/subscriptions","organizations_url":"https://api.github.com/users/christianklotz/orgs","repos_url":"https://api.github.com/users/christianklotz/repos","events_url":"https://api.github.com/users/christianklotz/events{/privacy}","received_events_url":"https://api.github.com/users/christianklotz/received_events","type":"User","site_admin":false},"labels":[],"state":"open","locked":false,"assignee":null,"assignees":[],"milestone":null,"comments":0,"created_at":"2018-02-05T12:38:02Z","updated_at":"2018-02-05T12:38:02Z","closed_at":null,"author_association":"NONE","body":"As we were trying to distinguish the API stage from which a Lambda function got called I noticed that `aws-local` _always_ defaults to `prod` and ignores the `StageName` specified in the SAM template.\r\n\r\n### Steps to reproduce behaviour\r\n\r\nFollow the [SAM documentation](https://github.com/awslabs/serverless-application-model/blob/master/versions/2016-10-31.md#awsserverlessapi) and set `StageName` of the API resource to `dev`.\r\n\r\n> **StageName `string`:** Required The name of the stage, which API Gateway uses as the first path segment in the invoke Uniform Resource Identifier (URI).\r\n\r\n```yaml\r\nResources:\r\n  MyAPI:\r\n    Type: \"AWS::Serverless::Api\"\r\n    Properties:\r\n      StageName: dev\r\n```\r\n\r\n### Expected result\r\nThe event should contain a stage value of `dev`.\r\n\r\n### Actual result\r\nThe event is set to `prod`.\r\n\r\nFrom what I can see the value is set to `prod` in the following line:\r\n\r\nhttps://github.com/awslabs/aws-sam-local/blob/f80c385e0d50a8de028d6cfde5cfa96c1d74d910/event.go#L92\r\n\r\nThis poses two questions:\r\n- How could stage be passed from the API to the runtime? As it stands, each Lambda function is initialised with a runtime which doesn't know anything about the API stage – and shouldn't since the same function could potentially be used by multiple APIs with different stage values. This suggests the request context itself could be initialised with a stage value derived from the API configuration. Currently the flow for a new event involves the following stages, showing there's no context passed in from the API to the invocation of the Lambda function:\r\n[`start()`](https://github.com/awslabs/aws-sam-local/blob/c4d34f2eb23c375274c374489cf723b0da5b87c3/start.go#L110) → [`Runtime.InvokeHTTP(string)`](https://github.com/awslabs/aws-sam-local/blob/1cfd626a52946c38722ce1718c87b44975d53cee/runtime.go#L510) → [`NewEvent(http.Request)`](https://github.com/awslabs/aws-sam-local/blob/f80c385e0d50a8de028d6cfde5cfa96c1d74d910/event.go#L92)\r\n- Would it be better to use a different default value than `prod` if `StageName` hasn't been set, something like `local` perhaps? Or, given that the documentation states that the attribute is _required_ it would be better to throw an error instead?"}}
{"actor":{"display_login":"christianklotz"}}