Amplify-cli: `GRAPHQLAPIIDOUTPUT` and `GRAPHQLAPIENDPOINTOUTPUT` are not set

Created on 12 Apr 2020  路  11Comments  路  Source: aws-amplify/amplify-cli

Describe the bug
GRAPHQLAPIIDOUTPUT and GRAPHQLAPIENDPOINTOUTPUT are not set

Amplify CLI Version
4.18.0

To Reproduce

  1. amplify function update
? Please select the Lambda Function you would want to update 
functionname
? Do you want to update permissions granted to this Lambda function to perform on other resources in your project? 
Yes
? Select the category 
api, storage
? Api has n resources in this project. Select the one you would like your Lambda to access 
apiname
? Select the operations you want to permit for apiname 
read
? Storage has n resources in this project. Select the one you would like your Lambda to access
storagename
? Select the operations you want to permit for storagename 
read, update
? Do you want to invoke this function on a recurring schedule?
No
? Do you want to edit the local lambda function now?
No
  1. print env value
console.log(process.env.API_APINAME_GRAPHQLAPIIDOUTPUT);
console.log(process.env.API_APINAME_GRAPHQLAPIENDPOINTOUTPUT);
console.log(process.env.STORAGE_STORAGENAME_BUCKETNAME);

Expected behavior

console.log(process.env.API_APINAME_GRAPHQLAPIIDOUTPUT);
-> "abcdef..."
console.log(process.env.API_APINAME_GRAPHQLAPIENDPOINTOUTPUT);
-> "https://abcdef....appsync-api.[region].amazonaws.com/graphql"
console.log(process.env.STORAGE_STORAGENAME_BUCKETNAME);
-> "storagename-env"

Actual behavior

console.log(process.env.API_APINAME_GRAPHQLAPIIDOUTPUT);
-> "apiapinameGraphQLAPIIdOutput"
console.log(process.env.API_APINAME_GRAPHQLAPIENDPOINTOUTPUT);
-> "apiapinameGraphQLAPIEndpointOutput"
console.log(process.env.STORAGE_STORAGENAME_BUCKETNAME);
-> "storagename-env"

Desktop (please complete the following information):

  • OS: [Ubuntu]
  • Node Version: [v12.14.1]

Additional context
amplify function update and attach dynamodb table occured below error.

Currently in UPDATE_ROLLBACK_IN_PROGRESS with reason: No export named apiapinameGraphQLAPIIdOutput:GetAtt:FooTable:Name found
functions not-reproducable pending-close-response-required

Most helpful comment

@edwardfoyle I'm getting the same error with Amplify CLI Version 4.18.1. When I run amplify mock it's returned: Could not find ref for "apideliveringHopeApiGraphQLAPIIdOutput". Using unsubstituted value. Could not find ref for "apideliveringHopeApiGraphQLAPIEndpointOutput". Using unsubstituted value.

I added the function using the command amplify add function.

This is the content of the root stack CFN file:

{
  'AWSTemplateFormatVersion': '2010-09-09',
  'Description': 'Root stack for the Amplify AWS CloudFormation provider',
  'Parameters':
    {
      'DeploymentBucketName':
        {
          'Description': 'Name of the common deployment bucket provided by the parent stack',
          'Type': 'String',
          'Default': 'DeploymentBucket',
        },
      'AuthRoleName': { 'Type': 'String', 'Default': 'AuthRoleName' },
      'UnauthRoleName': { 'Type': 'String', 'Default': 'UnauthRoleName' },
    },
  'Resources':
    {
      'DeploymentBucket':
        {
          'Type': 'AWS::S3::Bucket',
          'DeletionPolicy': 'Retain',
          'Properties': { 'BucketName': { 'Ref': 'DeploymentBucketName' } },
        },
      'AuthRole':
        {
          'Type': 'AWS::IAM::Role',
          'Properties':
            {
              'RoleName': { 'Ref': 'AuthRoleName' },
              'AssumeRolePolicyDocument':
                {
                  'Version': '2012-10-17',
                  'Statement':
                    [
                      {
                        'Sid': '',
                        'Effect': 'Deny',
                        'Principal':
                          { 'Federated': 'cognito-identity.amazonaws.com' },
                        'Action': 'sts:AssumeRoleWithWebIdentity',
                      },
                    ],
                },
            },
        },
      'UnauthRole':
        {
          'Type': 'AWS::IAM::Role',
          'Properties':
            {
              'RoleName': { 'Ref': 'UnauthRoleName' },
              'AssumeRolePolicyDocument':
                {
                  'Version': '2012-10-17',
                  'Statement':
                    [
                      {
                        'Sid': '',
                        'Effect': 'Deny',
                        'Principal':
                          { 'Federated': 'cognito-identity.amazonaws.com' },
                        'Action': 'sts:AssumeRoleWithWebIdentity',
                      },
                    ],
                },
            },
        },
      'apideliveringHopeApi':
        {
          'Type': 'AWS::CloudFormation::Stack',
          'Properties':
            {
              'TemplateURL': 'https://s3.amazonaws.com/amplify-delivering-hope-dev-05757-deployment/amplify-cfn-templates/api/cloudformation-template.json',
              'Parameters':
                {
                  'CreateAPIKey': 1,
                  'AppSyncApiName': 'deliveringHopeApi',
                  'DynamoDBBillingMode': 'PAY_PER_REQUEST',
                  'DynamoDBEnableServerSideEncryption': 'false',
                  'S3DeploymentBucket': 'amplify-delivering-hope-dev-05757-deployment',
                  'S3DeploymentRootKey': 'amplify-appsync-files/f1707bbc80fae28c61d20a6f994539ff9fed4ee4',
                  'env': 'dev',
                },
            },
        },
      'functionlistOtherCompanyProducts':
        {
          'Type': 'AWS::CloudFormation::Stack',
          'Properties':
            {
              'TemplateURL': 'https://s3.amazonaws.com/amplify-delivering-hope-dev-05757-deployment/amplify-cfn-templates/function/listOtherCompanyProducts-cloudformation-template.json',
              'Parameters':
                {
                  'apideliveringHopeApiGraphQLAPIIdOutput':
                    {
                      'Fn::GetAtt':
                        ['apideliveringHopeApi', 'Outputs.GraphQLAPIIdOutput'],
                    },
                  'apideliveringHopeApiGraphQLAPIEndpointOutput':
                    {
                      'Fn::GetAtt':
                        [
                          'apideliveringHopeApi',
                          'Outputs.GraphQLAPIEndpointOutput',
                        ],
                    },
                  'env': 'dev',
                },
            },
        },
    },
  'Outputs':
    {
      'Region':
        {
          'Description': 'CloudFormation provider root stack Region',
          'Value': { 'Ref': 'AWS::Region' },
          'Export': { 'Name': { 'Fn::Sub': '${AWS::StackName}-Region' } },
        },
      'StackName':
        {
          'Description': 'CloudFormation provider root stack ID',
          'Value': { 'Ref': 'AWS::StackName' },
          'Export': { 'Name': { 'Fn::Sub': '${AWS::StackName}-StackName' } },
        },
      'StackId':
        {
          'Description': 'CloudFormation provider root stack name',
          'Value': { 'Ref': 'AWS::StackId' },
          'Export': { 'Name': { 'Fn::Sub': '${AWS::StackName}-StackId' } },
        },
      'DeploymentBucketName':
        {
          'Description': 'CloudFormation provider root stack deployment bucket name',
          'Value': { 'Ref': 'DeploymentBucketName' },
          'Export':
            { 'Name': { 'Fn::Sub': '${AWS::StackName}-DeploymentBucketName' } },
        },
      'AuthRoleArn': { 'Value': { 'Fn::GetAtt': ['AuthRole', 'Arn'] } },
      'UnauthRoleArn': { 'Value': { 'Fn::GetAtt': ['UnauthRole', 'Arn'] } },
      'AuthRoleName': { 'Value': { 'Ref': 'AuthRole' } },
      'UnauthRoleName': { 'Value': { 'Ref': 'UnauthRole' } },
    },
}

All 11 comments

Hi @chakimar, does this only happen when you configure the permissions using update? Are you able to successfully configure the permissions during the amplify function add flow?

Hi @edwardfoyle , I tried amplify function add and successfully get GRAPHQLAPIIDOUTPUT and GRAPHQLAPIENDPOINTOUTPUT.

@chakimar I haven't been able to repro this. If possible, can you provide repro steps starting from a new project? Also, can you upload your root stack CFN (located in amplify/backend/awscloudformation/nested-cloudformation-stack.yml). Or if it contains sensitive information you can email it to [email protected] with this issue in the subject

@edwardfoyle I'm getting the same error with Amplify CLI Version 4.18.1. When I run amplify mock it's returned: Could not find ref for "apideliveringHopeApiGraphQLAPIIdOutput". Using unsubstituted value. Could not find ref for "apideliveringHopeApiGraphQLAPIEndpointOutput". Using unsubstituted value.

I added the function using the command amplify add function.

This is the content of the root stack CFN file:

{
  'AWSTemplateFormatVersion': '2010-09-09',
  'Description': 'Root stack for the Amplify AWS CloudFormation provider',
  'Parameters':
    {
      'DeploymentBucketName':
        {
          'Description': 'Name of the common deployment bucket provided by the parent stack',
          'Type': 'String',
          'Default': 'DeploymentBucket',
        },
      'AuthRoleName': { 'Type': 'String', 'Default': 'AuthRoleName' },
      'UnauthRoleName': { 'Type': 'String', 'Default': 'UnauthRoleName' },
    },
  'Resources':
    {
      'DeploymentBucket':
        {
          'Type': 'AWS::S3::Bucket',
          'DeletionPolicy': 'Retain',
          'Properties': { 'BucketName': { 'Ref': 'DeploymentBucketName' } },
        },
      'AuthRole':
        {
          'Type': 'AWS::IAM::Role',
          'Properties':
            {
              'RoleName': { 'Ref': 'AuthRoleName' },
              'AssumeRolePolicyDocument':
                {
                  'Version': '2012-10-17',
                  'Statement':
                    [
                      {
                        'Sid': '',
                        'Effect': 'Deny',
                        'Principal':
                          { 'Federated': 'cognito-identity.amazonaws.com' },
                        'Action': 'sts:AssumeRoleWithWebIdentity',
                      },
                    ],
                },
            },
        },
      'UnauthRole':
        {
          'Type': 'AWS::IAM::Role',
          'Properties':
            {
              'RoleName': { 'Ref': 'UnauthRoleName' },
              'AssumeRolePolicyDocument':
                {
                  'Version': '2012-10-17',
                  'Statement':
                    [
                      {
                        'Sid': '',
                        'Effect': 'Deny',
                        'Principal':
                          { 'Federated': 'cognito-identity.amazonaws.com' },
                        'Action': 'sts:AssumeRoleWithWebIdentity',
                      },
                    ],
                },
            },
        },
      'apideliveringHopeApi':
        {
          'Type': 'AWS::CloudFormation::Stack',
          'Properties':
            {
              'TemplateURL': 'https://s3.amazonaws.com/amplify-delivering-hope-dev-05757-deployment/amplify-cfn-templates/api/cloudformation-template.json',
              'Parameters':
                {
                  'CreateAPIKey': 1,
                  'AppSyncApiName': 'deliveringHopeApi',
                  'DynamoDBBillingMode': 'PAY_PER_REQUEST',
                  'DynamoDBEnableServerSideEncryption': 'false',
                  'S3DeploymentBucket': 'amplify-delivering-hope-dev-05757-deployment',
                  'S3DeploymentRootKey': 'amplify-appsync-files/f1707bbc80fae28c61d20a6f994539ff9fed4ee4',
                  'env': 'dev',
                },
            },
        },
      'functionlistOtherCompanyProducts':
        {
          'Type': 'AWS::CloudFormation::Stack',
          'Properties':
            {
              'TemplateURL': 'https://s3.amazonaws.com/amplify-delivering-hope-dev-05757-deployment/amplify-cfn-templates/function/listOtherCompanyProducts-cloudformation-template.json',
              'Parameters':
                {
                  'apideliveringHopeApiGraphQLAPIIdOutput':
                    {
                      'Fn::GetAtt':
                        ['apideliveringHopeApi', 'Outputs.GraphQLAPIIdOutput'],
                    },
                  'apideliveringHopeApiGraphQLAPIEndpointOutput':
                    {
                      'Fn::GetAtt':
                        [
                          'apideliveringHopeApi',
                          'Outputs.GraphQLAPIEndpointOutput',
                        ],
                    },
                  'env': 'dev',
                },
            },
        },
    },
  'Outputs':
    {
      'Region':
        {
          'Description': 'CloudFormation provider root stack Region',
          'Value': { 'Ref': 'AWS::Region' },
          'Export': { 'Name': { 'Fn::Sub': '${AWS::StackName}-Region' } },
        },
      'StackName':
        {
          'Description': 'CloudFormation provider root stack ID',
          'Value': { 'Ref': 'AWS::StackName' },
          'Export': { 'Name': { 'Fn::Sub': '${AWS::StackName}-StackName' } },
        },
      'StackId':
        {
          'Description': 'CloudFormation provider root stack name',
          'Value': { 'Ref': 'AWS::StackId' },
          'Export': { 'Name': { 'Fn::Sub': '${AWS::StackName}-StackId' } },
        },
      'DeploymentBucketName':
        {
          'Description': 'CloudFormation provider root stack deployment bucket name',
          'Value': { 'Ref': 'DeploymentBucketName' },
          'Export':
            { 'Name': { 'Fn::Sub': '${AWS::StackName}-DeploymentBucketName' } },
        },
      'AuthRoleArn': { 'Value': { 'Fn::GetAtt': ['AuthRole', 'Arn'] } },
      'UnauthRoleArn': { 'Value': { 'Fn::GetAtt': ['UnauthRole', 'Arn'] } },
      'AuthRoleName': { 'Value': { 'Ref': 'AuthRole' } },
      'UnauthRoleName': { 'Value': { 'Ref': 'UnauthRole' } },
    },
}

@glauberfc I believe the original issue was with the environment variables not being present when pushing the resources to the cloud whereas your issue looks like the variables are not present when mocking. @ammarkarachi is working on that. Some related issues are #4168, #4085, and #4012.

If you are also seeing errors that the variables are not defined when pushing to the cloud, please follow up with repro steps, as I have been unable to repro that issue

I'm facing the same problem. When I add a function and try to give it permissions to the api, cloudformation stack fails. Then I added the function with no permissions, then gave it permissions with amplify function update.

Any update on this issue? I'm also facing the same problem. I can access GraphQLAPIIdOutput but cannot access GraphQLAPIEndpointOutput. Although they are both present in the cfn template.
Screenshot 2020-05-12 at 03 48 32

I was facing a similar issue when adding/updating a function to the cloud.

On a new project I tried to grant permissions to API and Auth resources like this:

? Provide a friendly name for your resource to be used as a label for this category in the project: signupuser
? Provide the AWS Lambda function name: signupuser
? Choose the function runtime that you want to use: NodeJS
? Choose the function template that you want to use: Hello World
? Do you want to access other resources created in this project from your Lambda function? Yes
? Select the category api, auth
Api category has a resource called revampxp
? Select the operations you want to permit for revampxp create, read
Auth category has a resource called revampxp
? Select the operations you want to permit for revampxp read

As you can see, I had the same friendly name for the API and Auth resources.

When pushing the function I got the message: Template format error: Unresolved resource dependencies [authrevampxpUserPoolId] in the Resources block of the template

The function env variables were:
API_REVAMPXP_GRAPHQLAPIENDPOINTOUTPUT - Correctly set
API_REVAMPXP_GRAPHQLAPIIDOUTPUT - Correctly set
AUTH_REVAMPXP_USERPOOLID - Set with default value

Then I started a new project with exactly the same configuration and model.
I just let the Auth resource name generated by the cli. So that this name be different than the API resource name.

I added a new function:

? Provide a friendly name for your resource to be used as a label for this category in the project: signupuser
? Provide the AWS Lambda function name: signupuser
? Choose the function runtime that you want to use: NodeJS
? Choose the function template that you want to use: Hello World
? Do you want to access other resources created in this project from your Lambda function? Yes
? Select the category api, auth
Api category has a resource called revampxp
? Select the operations you want to permit for revampxp create, read
Auth category has a resource called revampxp4b40879a4b40879a
? Select the operations you want to permit for revampxp4b40879a4b40879a read

And it worked. No errors in the console, and env variables correctly set in the function.

So do you have resources with the same name?

I was facing a similar issue when adding/updating a function to the cloud.

On a new project I tried to grant permissions to API and Auth resources like this:

? Provide a friendly name for your resource to be used as a label for this category in the project: signupuser
? Provide the AWS Lambda function name: signupuser
? Choose the function runtime that you want to use: NodeJS
? Choose the function template that you want to use: Hello World
? Do you want to access other resources created in this project from your Lambda function? Yes
? Select the category api, auth
Api category has a resource called revampxp
? Select the operations you want to permit for revampxp create, read
Auth category has a resource called revampxp
? Select the operations you want to permit for revampxp read

As you can see, I had the same friendly name for the API and Auth resources.

When pushing the function I got the message: Template format error: Unresolved resource dependencies [authrevampxpUserPoolId] in the Resources block of the template

The function env variables were:
API_REVAMPXP_GRAPHQLAPIENDPOINTOUTPUT - Correctly set
API_REVAMPXP_GRAPHQLAPIIDOUTPUT - Correctly set
AUTH_REVAMPXP_USERPOOLID - Set with default value

Then I started a new project with exactly the same configuration and model.
I just let the Auth resource name generated by the cli. So that this name be different than the API resource name.

I added a new function:

? Provide a friendly name for your resource to be used as a label for this category in the project: signupuser
? Provide the AWS Lambda function name: signupuser
? Choose the function runtime that you want to use: NodeJS
? Choose the function template that you want to use: Hello World
? Do you want to access other resources created in this project from your Lambda function? Yes
? Select the category api, auth
Api category has a resource called revampxp
? Select the operations you want to permit for revampxp create, read
Auth category has a resource called revampxp4b40879a4b40879a
? Select the operations you want to permit for revampxp4b40879a4b40879a read

And it worked. No errors in the console, and env variables correctly set in the function.

So do you have resources with the same name?

Thanks for this. It seems the workaround for me was to actually select both auth and api as resources to be accessed. If i select only the api category I get env and region only as variables. Selecting both get's me the required apiKolaGraphQLGraphQLAPIEndpointOutput.

This issue has been automatically marked as stale because it has not had recent activity. It will be closed if no further activity occurs. Thank you for your contributions.

This issue has been automatically closed because of inactivity. Please open a new issue if you are still encountering problems.

Was this page helpful?
0 / 5 - 0 ratings