Testing the endpoints after deployment

I would like to run tests after sls deploy, so I can verify that the deployment completed successfully, and all components on my backend are working perfectly. To do so, I want to call the endpoints deployed to https://{restApiId}.execute-api.{region}.amazonaws.com/{stage}/{path}.

What is the easiest way to pass those parameters, or at least the base URL to a post deployment npm script?

For example, is there a way to export them to a file during deployment? I am considering writing a plugin to do that, but before that I would like to know if there is an easier and recommended way.

Thank you.

I think the “vanilla” way to do this would be parse the output of the sls deploy or sls info commands and test those.

You could also get the stack outputs (which include the endpoints) and test those, so you don’t have to parse text.

I was considering the same problem yesterday, as far as I can tell nothing currently exists to output the stack outputs to a file. In bash I managed to come up with this:

serverless info --verbose | grep ServiceEndpoint | sed s/ServiceEndpoint\:\ //g | awk '{print $1"/your-path"}' | xargs -n1 curl

Not the prettiest, and I’m trying to work a way to make it into a plugin at the moment or at least aliasable in bash!

1 Like

Thank you @redroot, sls info seems to be the good way to start. However, if you have a custom domain and use the serverless-domain-manager plugin, the name of the domain is not printed in the info output. But I guess that is something I should report to the plugin author.

I highly appreciate your efforts embedding this to a plugin.

@balassy that’s a shame, does serverless info --verbose also not print it out?

@redroot: No, even with the --verbose parameter the custom domain does not get printed to the output, so I’ve created an issue for that: https://github.com/amplify-education/serverless-domain-manager/issues/35

Thanks to @jconstance-amplify the 1.1.16 version of the serverless-domain-manager package prints the name of the custom domain in the sls info --verbose output.

FYI: I started another discussion on producing a computer friendly output in sls info: