0
votes

I trying to build a jenkins pipeline that will deploy some common AWS resources and then will deploy the specific service resources.

Here is the common resources part, is being deployed with success.

resources:
  Resources:
    GoatfolioUserPool:
      Type: 'AWS::Cognito::UserPool'
      Properties:
        AccountRecoverySetting:
          RecoveryMechanisms:
            - Name: verified_email
              Priority: 1
        AutoVerifiedAttributes:
          - email
        EmailVerificationSubject: "GOATFOLIO - Verifique seu e-mail"
        Policies:
          PasswordPolicy:
            MinimumLength: 6
            RequireLowercase: true
            RequireNumbers: true
            RequireSymbols: true
            RequireUppercase: true
            TemporaryPasswordValidityDays: 1
        Schema:
          - AttributeDataType: String
            Name: email
            Required: true
          - AttributeDataType: String
            Name: given_name
            Required: true
        AliasAttributes:
          - email
        UsernameConfiguration:
          CaseSensitive: false
        UserPoolName: "goatfolio"

    ApiGatewayRestApi:
      Type: AWS::ApiGateway::RestApi
          Properties:
        Name: ApiGatewayRestApi

    ApiGatewayAuthorizer:
      Type: AWS::ApiGateway::Authorizer
      Properties:
        AuthorizerResultTtlInSeconds: 10
        IdentitySource: method.request.header.Authorization
        Name: GoatCognitoAuthorizer
        RestApiId:
          Ref: ApiGatewayRestApi
        Type: COGNITO_USER_POOLS
        ProviderARNs:
          - {"Fn::Join": ["", ["arn:aws:cognito-idp:", {Ref: "AWS::Region"}, ":", {Ref: "AWS::AccountId"}, ":userpool/goatfolio", Ref: GoatfolioUserPool]]}

  Outputs:
    ApiGatewayAuthorizerOutput:
      Value:
        Ref: ApiGatewayAuthorizer
      Export:
        Name: ${self:provider.stage}-ApiGatewayAuthorizerOutput

The specific part:

functions:
  getConsolidated:
    handler: handlers.consolidate_investments_handler
    events:
      - http:
          path: portfolio/
          method: get
          authorizer:
            type: COGNITO_USER_POOLS
            authorizerId:
              Ref: {'Fn::ImportValue': '${self:provider.stage}-ApiGatewayAuthorizerOutput'}

I'm trying to use this ImportValue but it's giving this error:

Error: The CloudFormation template is invalid: Template error: every Ref object must have a single String value.

I've tried some other things as well, unsuccessfully.

There is a way to print the return of the ImportValue so I can understand what's happening?

I'm doing something terrible wrong?

Thanks in advance.

1

1 Answers

1
votes

You can view export value of '${self:provider.stage}-ApiGatewayAuthorizerOutput' in your stacks' console, in Outputs tab, or in CloudFormation console in Exports menu.

!Ref in your context can't be used, as the imported value is from other stack. If you just want to use imported value, then there is no need for !Ref.

You can try the following:

    authorizerId: {'Fn::ImportValue': '${self:provider.stage}-ApiGatewayAuthorizerOutput'}