I'm having trouble setting a customDomain in a Sta...
# help
m
I'm having trouble setting a customDomain in a StaticSite. Here's the code:
Copy code
import * as sst from "@serverless-stack/resources";
import { StaticSiteErrorOptions } from "@serverless-stack/resources";

export default class MyStack extends sst.Stack {
  constructor(scope, id, props) {
    super(scope, id, props);

    // Create a HTTP API
    const api = new sst.Api(this, "Api", {
      customDomain: {
        domainName: "<http://api.blah.ca|api.blah.ca>",
        hostedZone: "<http://blah.ca|blah.ca>"
      },
      routes: {
        "GET /": "src/lambda.handler",
      },
    });

    // Show the endpoint in the output
    this.addOutputs({
      "ApiEndpoint": api.url,
      "CustomDomainUrl": api.customDomainUrl,
    });

    const site = new sst.StaticSite(this, "Nuxt Site", {
      path: "frontend",
      buildOutput: "dist",
      buildCommand: "npm run generate",
      errorPage: StaticSiteErrorOptions.REDIRECT_TO_INDEX_PAGE,
      customDomain: {
        domainName: "<http://dev.blah.ca|dev.blah.ca>",
        hostedZone: "<http://blah.ca|blah.ca>",
      },
    });

    this.addOutputs({
      "CloudFront URL": site.url,
    })
  }
}
The failure message is:
Copy code
MarkDev-serverless-stack-test-my-stack | CREATE_FAILED | Custom::SSTBucketDeployment | NuxtSiteCustomResource71AA1EA4 Received response status [FAILED] from custom resource. Message returned: 'NoneType' object is not iterable (RequestId: 63a4abb9-d153-4bb3-9962-b75b5f978c38)
If I comment out the customDomain passed into the StaticSite, it works fine, but not under the domain I want to use.
t
Does it work for the custom domain in the sst.Api?
m
Yes. The API bit works great. Sorry. That's why included it.
f
Hey @Mark Faulkner, if you now uncomment the
customDomain
, does re-deploying it work now?
m
Trying it now.
Afraid not. Result is the same:
Copy code
MarkDev-serverless-stack-test-my-stack | CREATE_FAILED | Custom::SSTBucketDeployment | NuxtSiteCustomResource71AA1EA4 Received response status [FAILED] from custom resource. Message returned: 'NoneType' object is not iterable (RequestId: 63a4abb9-d153-4bb3-9962-b75b5f978c38)
Do I have to
npm update
something?
f
I see. Maybe lets take a quick look at the CloudWatch logs for this custom resource. That should tell us the root cause.
Here’re the steps to pull up the logs: 1. go to ur CloudFormation console 2. look for and select the stack
MarkDev-serverless-stack-test-my-stack
3. select the
Resources
tab 4. look for the resource of type
AWS::Lambda::Function
and with
S3Handler
in the logical id. 5. copy the physical id 6. go to ur CloudWatch console 7. select log groups 8. look for the log group with function name from step 5 9. select the log group 10. select the latest log stream 11. paste all the logs here
sorry for the long list of steps… navigating within AWS console can be a bit of work
t
I actually click through to the function page and then click "view logs" from their monitoring tab
m
Thanks, and for the long list of steps too. I'll see what I can find.
There are no resources of type
AWS::Lambda::Functions
with
S3Handler
in the logical id.
Looking at the events, here's the last success, followed by the first errors:
Copy code
2021-10-26 09:25:08 UTC-0600	MarkDev-serverless-stack-test-my-stack	ROLLBACK_IN_PROGRESS	The following resource(s) failed to create: [NuxtSiteCustomResource71AA1EA4, NuxtSiteAliasRecordE180C995]. Rollback requested by user.
2021-10-26 09:25:07 UTC-0600	NuxtSiteAliasRecordE180C995	CREATE_FAILED	Resource creation cancelled
2021-10-26 09:25:06 UTC-0600	NuxtSiteCustomResource71AA1EA4	CREATE_FAILED	Received response status [FAILED] from custom resource. Message returned: 'NoneType' object is not iterable (RequestId: 0f2d5e05-7443-4f99-8bc0-3e66a6c02915)
2021-10-26 09:25:06 UTC-0600	NuxtSiteCustomResource71AA1EA4	CREATE_IN_PROGRESS	Resource creation Initiated
The rest is all deletes from the rollback.
Aha! Here's the log of the Lambda function that fails:
Copy code
START RequestId: 74243668-5568-4077-95c5-e9cc80ed049e Version: $LATEST
[INFO]	2021-10-22T16:58:38.400Z		Found credentials in environment variables.
[INFO]	2021-10-22T16:58:38.492Z	74243668-5568-4077-95c5-e9cc80ed049e	{'RequestType': 'Create', 'ServiceToken': 'arn:aws:lambda:ca-central-1:876140884907:function:MarkDev-serverless-stack--NuxtSiteCustomResourceHa-cQwKo3V5UGwa', 'ResponseURL': '<https://cloudformation-custom-resource-response-cacentral1.s3.ca-central-1.amazonaws.com/arn%3Aaws%3Acloudformation%3Aca-central-1%3A876140884907%3Astack/MarkDev-serverless-stack-test-my-stack/aa84c7d0-3358-11ec-93ac-060303870d22%7CNuxtSiteCustomResource71AA1EA4%7C63a4abb9-d153-4bb3-9962-b75b5f978c38?X-Amz-Algorithm=AWS4-HMAC-SHA256&X-Amz-Date=20211022T165837Z&X-Amz-SignedHeaders=host&X-Amz-Expires=7200&X-Amz-Credential=AKIAVYHELKCFQNTLEBPQ%2F20211022%2Fca-central-1%2Fs3%2Faws4_request&X-Amz-Signature=704bc5d678c3e3af0e7259d834f2dc5bac04f3fd360b94e6ee75fc5b9061c18d>', 'StackId': 'arn:aws:cloudformation:ca-central-1:876140884907:stack/MarkDev-serverless-stack-test-my-stack/aa84c7d0-3358-11ec-93ac-060303870d22', 'RequestId': '63a4abb9-d153-4bb3-9962-b75b5f978c38', 'LogicalResourceId': 'NuxtSiteCustomResource71AA1EA4', 'ResourceType': 'Custom::SSTBucketDeployment', 'ResourceProperties': {'ServiceToken': 'arn:aws:lambda:ca-central-1:876140884907:function:MarkDev-serverless-stack--NuxtSiteCustomResourceHa-cQwKo3V5UGwa', 'DestinationBucketName': 'markdev-serverless-stack-t-nuxtsitebucket0f527c37-6lq7ulj2b1no', 'DestinationBucketKeyPrefix': 'deploy-d41d8cd98f00b204e9800998ecf8427e', 'DistributionId': 'E1S011HPYR5S4M', 'DistributionPaths': ['/*'], 'ReplaceValues': [], 'Sources': [], 'FileOptions': []}}
[INFO]	2021-10-22T16:58:38.492Z	74243668-5568-4077-95c5-e9cc80ed049e	| s3_dest: <s3://markdev-serverless-stack-t-nuxtsitebucket0f527c37-6lq7ulj2b1no/deploy-d41d8cd98f00b204e9800998ecf8427e>
[INFO]	2021-10-22T16:58:38.492Z	74243668-5568-4077-95c5-e9cc80ed049e	| old_s3_dest: None
[INFO]	2021-10-22T16:58:38.492Z	74243668-5568-4077-95c5-e9cc80ed049e	| s3_deploy_all
[INFO]	2021-10-22T16:58:38.493Z	74243668-5568-4077-95c5-e9cc80ed049e	| s3_deploy_all: uploader function: MarkDev-serverless-stack--NuxtSiteCustomResourceUp-m5WTFDLmSeil
[INFO]	2021-10-22T16:58:38.493Z	74243668-5568-4077-95c5-e9cc80ed049e	| cleanup old deploys
[ERROR]	2021-10-22T16:58:38.576Z	74243668-5568-4077-95c5-e9cc80ed049e	'NoneType' object is not iterable
Traceback (most recent call last):
File "/var/task/index.py", line 104, in handler
cleanup_old_deploys(dest_bucket_name, dest_bucket_prefix, old_dest_bucket_prefix)
File "/var/task/index.py", line 179, in cleanup_old_deploys
for o in result.get('CommonPrefixes'):
TypeError: 'NoneType' object is not iterable
[ERROR]	2021-10-22T16:58:38.576Z	74243668-5568-4077-95c5-e9cc80ed049e	| cfn_error: 'NoneType' object is not iterable
[INFO]	2021-10-22T16:58:38.577Z	74243668-5568-4077-95c5-e9cc80ed049e	<https://cloudformation-custom-resource-response-cacentral1.s3.ca-central-1.amazonaws.com/arn%3Aaws%3Acloudformation%3Aca-central-1%3A876140884907%3Astack/MarkDev-serverless-stack-test-my-stack/aa84c7d0-3358-11ec-93ac-060303870d22%7CNuxtSiteCustomResource71AA1EA4%7C63a4abb9-d153-4bb3-9962-b75b5f978c38?X-Amz-Algorithm=AWS4-HMAC-SHA256&X-Amz-Date=20211022T165837Z&X-Amz-SignedHeaders=host&X-Amz-Expires=7200&X-Amz-Credential=AKIAVYHELKCFQNTLEBPQ%2F20211022%2Fca-central-1%2Fs3%2Faws4_request&X-Amz-Signature=704bc5d678c3e3af0e7259d834f2dc5bac04f3fd360b94e6ee75fc5b9061c18d>
[INFO]	2021-10-22T16:58:38.577Z	74243668-5568-4077-95c5-e9cc80ed049e	| response body:
{
    "Status": "FAILED",
    "Reason": "'NoneType' object is not iterable",
    "PhysicalResourceId": "2021/10/22/[$LATEST]5f1c1aeb40ee470c9b743e9f86578210",
    "StackId": "arn:aws:cloudformation:ca-central-1:876140884907:stack/MarkDev-serverless-stack-test-my-stack/aa84c7d0-3358-11ec-93ac-060303870d22",
    "RequestId": "63a4abb9-d153-4bb3-9962-b75b5f978c38",
    "LogicalResourceId": "NuxtSiteCustomResource71AA1EA4",
    "NoEcho": false,
    "Data": {}
}

[INFO]	2021-10-22T16:58:38.616Z	74243668-5568-4077-95c5-e9cc80ed049e	| status code: OK
END RequestId: 74243668-5568-4077-95c5-e9cc80ed049e
REPORT RequestId: 74243668-5568-4077-95c5-e9cc80ed049e	Duration: 127.04 ms	Billed Duration: 128 ms	Memory Size: 1024 MB	Max Memory Used: 80 MB	Init Duration: 472.19 ms	
START RequestId: cf6a2525-2c88-4967-96cb-87fc2c9ad8f9 Version: $LATEST
[INFO]	2021-10-22T16:58:43.967Z	cf6a2525-2c88-4967-96cb-87fc2c9ad8f9	{'RequestType': 'Delete', 'ServiceToken': 'arn:aws:lambda:ca-central-1:876140884907:function:MarkDev-serverless-stack--NuxtSiteCustomResourceHa-cQwKo3V5UGwa', 'ResponseURL': '<https://cloudformation-custom-resource-response-cacentral1.s3.ca-central-1.amazonaws.com/arn%3Aaws%3Acloudformation%3Aca-central-1%3A876140884907%3Astack/MarkDev-serverless-stack-test-my-stack/aa84c7d0-3358-11ec-93ac-060303870d22%7CNuxtSiteCustomResource71AA1EA4%7C975f097b-1a7b-4c74-9c4c-15092e9bb52c?X-Amz-Algorithm=AWS4-HMAC-SHA256&X-Amz-Date=20211022T165843Z&X-Amz-SignedHeaders=host&X-Amz-Expires=7200&X-Amz-Credential=AKIAVYHELKCFQNTLEBPQ%2F20211022%2Fca-central-1%2Fs3%2Faws4_request&X-Amz-Signature=4692bc272a333d5e1aa8635310fb5e6b63ab761ab90113b5c0cbae117d7a3029>', 'StackId': 'arn:aws:cloudformation:ca-central-1:876140884907:stack/MarkDev-serverless-stack-test-my-stack/aa84c7d0-3358-11ec-93ac-060303870d22', 'RequestId': '975f097b-1a7b-4c74-9c4c-15092e9bb52c', 'LogicalResourceId': 'NuxtSiteCustomResource71AA1EA4', 'PhysicalResourceId': '2021/10/22/[$LATEST]5f1c1aeb40ee470c9b743e9f86578210', 'ResourceType': 'Custom::SSTBucketDeployment', 'ResourceProperties': {'ServiceToken': 'arn:aws:lambda:ca-central-1:876140884907:function:MarkDev-serverless-stack--NuxtSiteCustomResourceHa-cQwKo3V5UGwa', 'DestinationBucketName': 'markdev-serverless-stack-t-nuxtsitebucket0f527c37-6lq7ulj2b1no', 'DestinationBucketKeyPrefix': 'deploy-d41d8cd98f00b204e9800998ecf8427e', 'DistributionId': 'E1S011HPYR5S4M', 'DistributionPaths': ['/*'], 'ReplaceValues': [], 'Sources': [], 'FileOptions': []}}
[INFO]	2021-10-22T16:58:43.967Z	cf6a2525-2c88-4967-96cb-87fc2c9ad8f9	| s3_dest: <s3://markdev-serverless-stack-t-nuxtsitebucket0f527c37-6lq7ulj2b1no/deploy-d41d8cd98f00b204e9800998ecf8427e>
[INFO]	2021-10-22T16:58:43.967Z	cf6a2525-2c88-4967-96cb-87fc2c9ad8f9	| old_s3_dest: None
[INFO]	2021-10-22T16:58:43.967Z	cf6a2525-2c88-4967-96cb-87fc2c9ad8f9	| aws s3 rm <s3://markdev-serverless-stack-t-nuxtsitebucket0f527c37-6lq7ulj2b1no/deploy-d41d8cd98f00b204e9800998ecf8427e> --recursive
[INFO]	2021-10-22T16:59:26.064Z	cf6a2525-2c88-4967-96cb-87fc2c9ad8f9	<https://cloudformation-custom-resource-response-cacentral1.s3.ca-central-1.amazonaws.com/arn%3Aaws%3Acloudformation%3Aca-central-1%3A876140884907%3Astack/MarkDev-serverless-stack-test-my-stack/aa84c7d0-3358-11ec-93ac-060303870d22%7CNuxtSiteCustomResource71AA1EA4%7C975f097b-1a7b-4c74-9c4c-15092e9bb52c?X-Amz-Algorithm=AWS4-HMAC-SHA256&X-Amz-Date=20211022T165843Z&X-Amz-SignedHeaders=host&X-Amz-Expires=7200&X-Amz-Credential=AKIAVYHELKCFQNTLEBPQ%2F20211022%2Fca-central-1%2Fs3%2Faws4_request&X-Amz-Signature=4692bc272a333d5e1aa8635310fb5e6b63ab761ab90113b5c0cbae117d7a3029>
[INFO]	2021-10-22T16:59:26.065Z	cf6a2525-2c88-4967-96cb-87fc2c9ad8f9	| response body:
{
    "Status": "SUCCESS",
    "Reason": "See the details in CloudWatch Log Stream: 2021/10/22/[$LATEST]5f1c1aeb40ee470c9b743e9f86578210",
    "PhysicalResourceId": "2021/10/22/[$LATEST]5f1c1aeb40ee470c9b743e9f86578210",
    "StackId": "arn:aws:cloudformation:ca-central-1:876140884907:stack/MarkDev-serverless-stack-test-my-stack/aa84c7d0-3358-11ec-93ac-060303870d22",
    "RequestId": "975f097b-1a7b-4c74-9c4c-15092e9bb52c",
    "LogicalResourceId": "NuxtSiteCustomResource71AA1EA4",
    "NoEcho": false,
    "Data": {}
}

[INFO]	2021-10-22T16:59:26.098Z	cf6a2525-2c88-4967-96cb-87fc2c9ad8f9	| status code: OK
END RequestId: cf6a2525-2c88-4967-96cb-87fc2c9ad8f9
REPORT RequestId: cf6a2525-2c88-4967-96cb-87fc2c9ad8f9	Duration: 42134.13 ms	Billed Duration: 42135 ms	Memory Size: 1024 MB	Max Memory Used: 170 MB
t
can you verify the bucket for the deploy exists?
m
That would be named something like
MarkDev-serverless-stack-test-my-stack
, right?
t
you can look to see what your cloudfront distribution is pointing at
and if it's there, I'm curious what's in it
m
There's no CloudFront distribution and no S3 bucket. When I run a deploy, the S3 bucket appears, a CloudFront distribution for the dev API appears, as does the S3 bucket markdev-serverless-stack-t-nuxtsitebucket0f527c37-1cmtwvhth1lkr, but it all disappears the deployment is rolled back.
In case it matters, I never saw any objects in the deployment S3 bucket while it existed.
t
hm I'm stumped, maybe Frank has an idea
afaik that script isn't effected by custom domains so wonder why it's failing
m
I'll try just running locally (ie.
npx sst start
).
And it works fine, but that's without the custom domain.
So where do the SST Python files end up? Could I modify them to add more debugging output and run another deploy?
f
Thanks for looking into this @thdxr.
Hey @Mark Fox, lemme take a quick look at the CW logs u shared.
m
No problem. Thanks to both of you for looking at this.
f
Btw, which version of SST r u using?
m
0.1.0
f
Can you try running
npx sst --version
?
m
Oops. Sure:
Copy code
SST: 0.45.1
CDK: 1.125.0
f
Can you update SST to
0.49.2
and give it another try?
We fixed an issue that might be related to this.
You can update using:
Copy code
$ npx sst update 0.49.2
$ yarn sst update 0.49.2
depending on the packager u r using
m
It's updating to latest now.
The deploy is running now.
And that fixed that problem. Thanks! But it didn't upload anything to the bucket. That might just have been my mistake. I'll make a point to upgrade before I bother anyone next time. On the plus side, I have a better understanding of what is going on under the hood.
f
Oh nice… glad u r making progress.
No worries at all!