{"action":"opened","issue":{"url":"https://api.github.com/repos/awslabs/aws-sam-cli/issues/894","repository_url":"https://api.github.com/repos/awslabs/aws-sam-cli","labels_url":"https://api.github.com/repos/awslabs/aws-sam-cli/issues/894/labels{/name}","comments_url":"https://api.github.com/repos/awslabs/aws-sam-cli/issues/894/comments","events_url":"https://api.github.com/repos/awslabs/aws-sam-cli/issues/894/events","html_url":"https://github.com/awslabs/aws-sam-cli/issues/894","id":394494618,"node_id":"MDU6SXNzdWUzOTQ0OTQ2MTg=","number":894,"title":"are dynamic references supposed to work in local commands?","user":{"login":"rhbecker","id":224732,"node_id":"MDQ6VXNlcjIyNDczMg==","avatar_url":"https://avatars2.githubusercontent.com/u/224732?v=4","gravatar_id":"","url":"https://api.github.com/users/rhbecker","html_url":"https://github.com/rhbecker","followers_url":"https://api.github.com/users/rhbecker/followers","following_url":"https://api.github.com/users/rhbecker/following{/other_user}","gists_url":"https://api.github.com/users/rhbecker/gists{/gist_id}","starred_url":"https://api.github.com/users/rhbecker/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/rhbecker/subscriptions","organizations_url":"https://api.github.com/users/rhbecker/orgs","repos_url":"https://api.github.com/users/rhbecker/repos","events_url":"https://api.github.com/users/rhbecker/events{/privacy}","received_events_url":"https://api.github.com/users/rhbecker/received_events","type":"User","site_admin":false},"labels":[],"state":"open","locked":false,"assignee":null,"assignees":[],"milestone":null,"comments":0,"created_at":"2018-12-27T21:48:29Z","updated_at":"2018-12-27T21:48:29Z","closed_at":null,"author_association":"NONE","body":"### Description\r\n\r\nI'm not certain whether this is a bug, feature request, or user error. I'm attempting to [use dynamic references to specify template values](https://docs.aws.amazon.com/AWSCloudFormation/latest/UserGuide/dynamic-references.html); more specifically, I'm attempting to use them to specify environment variable values for my function. So far, instead of the reference getting parsed and replaced by the looked up value, I'm getting the literal reference back.\r\n\r\n### Steps to reproduce\r\n\r\nVia the cli, I execute ` aws ssm get-parameter --name ExpValue` and the following is returned, as expected ...\r\n\r\n```JSON\r\n{\r\n    \"Parameter\": {\r\n        \"Name\": \"ExpValue\",\r\n        \"Type\": \"String\",\r\n        \"Value\": \"helloz!\",\r\n        \"Version\": 1,\r\n        \"LastModifiedDate\": 1545939038.102,\r\n        \"ARN\": \"arn:aws:ssm:us-west-2:668206432575:parameter/ExpValue\"\r\n    }\r\n}\r\n```\r\nIn my template, I attempt 2 different ways of accessing the param. I haven't yet found any documentation to support the `SSM_VIA_PARAM` approach. I only included that because it apparently worked for [this person](https://github.com/awslabs/serverless-application-model/issues/48#issuecomment-414391433). For the `SSM_DIRECT` approach, I believe I'm following the [instructions in the cloudformation docs](https://docs.aws.amazon.com/AWSCloudFormation/latest/UserGuide/dynamic-references.html#dynamic-references-ssm), but could be doing something wrong.\r\n\r\n```YAML\r\nAWSTemplateFormatVersion: 2010-09-09\r\nTransform: AWS::Serverless-2016-10-31\r\nDescription: ssm-experiment\r\nGlobals:\r\n  Function:\r\n    CodeUri: lambda/src/\r\n    Runtime: nodejs8.10\r\n    Timeout: 3\r\nParameters:\r\n  SSM:\r\n    Type: 'AWS::SSM::Parameter::Value<String>'\r\n    Default: ExpValue\r\nResources:\r\n  ExperimentFunction:\r\n    Type: AWS::Serverless::Function\r\n    Properties:\r\n      Handler: experiment.handler\r\n      Environment:\r\n        Variables:\r\n          SSM_DIRECT: '{{resolve:ssm:ExpValue:1}}'\r\n          SSM_VIA_PARAM: !Ref SSM\r\n          STATIC: hello\r\n      Events:\r\n        Index:\r\n          Type: Api\r\n          Properties:\r\n            Path: /\r\n            Method: get\r\n```\r\n\r\nIn my function, I just spit out the environment variable values ...\r\n\r\n```JavaScript\r\nexports.handler = async (event, context) => {\r\n  try {\r\n    return {\r\n      statusCode: 200,\r\n      body: JSON.stringify({\r\n        ssm_direct: process.env.SSM_DIRECT,\r\n        ssm_via_param: process.env.SSM_VIA_PARAM,\r\n        static: process.env.STATIC,\r\n      }),\r\n    };\r\n  } catch (err) {\r\n    return err;\r\n  }\r\n};\r\n```\r\n\r\n### Observed result\r\n\r\nWhen I execute `sam local start-api` and then visit http://127.0.0.1:3000/, I see ...\r\n\r\n```JSON\r\n{\r\n  \"ssm_direct\": \"{{resolve:ssm:ExpValue:1}}\",\r\n  \"ssm_via_param\": \"ExpValue\",\r\n  \"static\": \"hello\"\r\n}\r\n```\r\n\r\n### Expected result\r\n\r\nI expected `ssm_direct` and `ssm_via_param` to hold the value \"helloz!\".\r\n\r\n### Other notes\r\n\r\nI did observe a note in the docs I've linked a couple times that might be relevant, but I don't understand what it means:\r\n\r\n> For transforms, such as AWS::Include and AWS::Serverless, AWS CloudFormation does not resolve dynamic references prior to invoking any transforms. Rather, AWS CloudFormation passes the literal string of the dynamic reference to the transform. Dynamic references (including those inserted into the processed template as the result of a transform) are resolved when you execute the change set using the template.\r\n\r\n### Additional environment details (Ex: Windows, Mac, Amazon Linux etc)\r\n\r\n1. OS: Windows 10\r\n2. `sam --version`: SAM CLI, version 0.10.0\r\n"}}
{"actor":{"display_login":"rhbecker"}}