Skip to content

Fn::GetAtt seems to not working #41

@ademoverflow

Description

@ademoverflow

Hello !

I am facing an issue where I create a Cloudfront distribution and I cannot get the DomainName of the resource with GetAtt.

Here is my serverless.yaml:

service: my-service

useDotenv: true

package:
  individually: true

plugins:
  - serverless-export-env

provider:
  name: aws
  region: ${opt:region, "eu-west-1"}
  stage: ${opt:stage, "staging"}
  environment:
    CLOUDFRONT_WEBAPP_ID: !Ref WebAppCloudFrontDistribution
    # THE LINE BELLOW CAUSES THE ERROR AT THE END OF THE ISSUE:
    CLOUDFRONT_WEBAPP_URL:
      Fn::GetAtt:
        - WebAppCloudFrontDistribution
        - DomainName

custom:
  bucketName: my-awesome-bucket-789456
  export-env:
    filename: .env.${self:provider.stage}
    overwrite: true

resources:
  Resources:
    WebAppS3Bucket:
      Type: AWS::S3::Bucket
      Properties:
        BucketName: ${self:custom.bucketName}
        AccessControl: PublicRead
        WebsiteConfiguration:
          IndexDocument: index.html
          ErrorDocument: 404.html
    WebAppS3BucketPolicy:
      Type: AWS::S3::BucketPolicy
      Properties:
        Bucket:
          Ref: WebAppS3Bucket
        PolicyDocument:
          Statement:
            - Sid: PublicReadGetObject
              Effect: Allow
              Principal: "*"
              Action:
                - s3:GetObject
              Resource:
                "Fn::Join":
                  - ""
                  - - "arn:aws:s3:::"
                    - Ref: WebAppS3Bucket
                    - /*
    WebAppCloudFrontDistribution:
      Type: AWS::CloudFront::Distribution
      Properties:
        DistributionConfig:
          Origins:
            - DomainName:
                !Select [2, !Split ["/", !GetAtt WebAppS3Bucket.WebsiteURL]]
              Id: S3-Website-example.com.s3-website-${self:provider.region}.amazonaws.com
              CustomOriginConfig:
                HTTPPort: 80
                HTTPSPort: 443
                OriginProtocolPolicy: http-only
          Enabled: true
          DefaultCacheBehavior:
            AllowedMethods:
              - DELETE
              - GET
              - HEAD
              - OPTIONS
              - PATCH
              - POST
              - PUT
            TargetOriginId: S3-Website-example.com.s3-website-${self:provider.region}.amazonaws.com
            ForwardedValues:
              QueryString: false
              Cookies:
                Forward: none
            ViewerProtocolPolicy: redirect-to-https

package.json

{
  "name": "my-service",
  "private": true,
  "version": "1.0.0",
  "dependencies": {},
  "devDependencies": {
    "serverless-export-env": "^2.0.0"
  }
}

Firt I run: sls deploy --stage dev --region eu-west-1 and everything is ok, my stack my-service-dev contains the resources.

Then, when I run sls export-env --stage dev --region eu-west-1 I get the following result:

Fn::GetAttResolvers not found in params file: WebAppCloudFrontDistribution.DomainName

So I cannot fetch the cloudfront domain name and export it ...

Note: Ref works like a charm ! I can fetch the cloudfront ID without any error.

What am I doing wrong ?

Metadata

Metadata

Assignees

No one assigned

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions