Unable to register a pjsip softphone

very new to Asterisk here, and trying to get my first phone setup.
while configuring a Xlite phonephone to register with Asterisk I am getting the error

[Aug 31 03:48:32] NOTICE[1966]: res_pjsip/pjsip_distributor.c:649 log_failed_request: Request ‘REGISTER’ from ‘sip:1001@1.2.3.4’ failed for ‘5.6.7.8:51897’ (callid: 86895MDQ5MzY4MzhhNzM4MWUwYjA4OTU1NmJkNGEwODM2MDg) - Failed to authenticate
[Aug 31 03:48:33] NOTICE[1966]: res_pjsip/pjsip_distributor.c:649 log_failed_request: Request ‘REGISTER’ from ‘sip:1001@1.2.3.4’ failed for ‘5.6.7.8:51897’ (callid: 86895MDg0OTE0MjVjZTA0YzExMDc2NmRiYWY4ZDZkOTUxZjY) - Failed to authenticate

The IP : 1.2.3.4 is a public IP from Amazon ( port open to the Asterisk are UDP 5060,UDP10000-20000,UDP4569)
The IP : 4.5.6.7 is my home IP, I want to Xlite softphone to register with my Asterisk on Amazon

my entire PJSIP look like below ( I backup the original pjsip.conf and created a new pjsip)
[transport-udp]
type=transport
bind=0.0.0.0
protocol=udp

[1001]
type=endpoint
transport=transport-udp
context=default
disallow=all
allow=ulaw
iaors=1001
auth=1001

[1001]
type=auth
auth_type=userpass
username=1001
md5_cred=12345

[1001]
type=aor
max_contacts=1

Asterisk is complaining about authentication failure, try to replace on the [auth] section md5_cred by
password= 12345 , reload your config and test

different error now , but still cannot register.

<— Transmitting SIP response (537 bytes) to UDP:5.6.7.8:65340 —>
SIP/2.0 401 Unauthorized
Via: SIP/2.0/UDP 5.6.7.8:65340;rport=65340;received=5.6.7.8;branch=z9hG4bK-524287-1—9d73402749583a0f
Call-ID: 86895NDU5ZDQ2NjBiMjMwMDNkMWRhMjA1OGRkYmMzOTNkNmY
From: sip:1001@1.2.3.4;tag=c2ed105b
To: sip:1001@1.2.3.4;tag=z9hG4bK-524287-1—9d73402749583a0f
CSeq: 2 REGISTER
WWW-Authenticate: Digest realm=“asterisk”,nonce=“1504152525/fe545d776bded858870aa4b134700126”,opaque=“02bfd66d44b9b5e3”,algorithm=md5,qop="auth"
Server: Asterisk PBX 13.17.0
Content-Length: 0

I dont use pjsip, just used for testing popurses , but this configuration should work

[transport-udp]
type=transport
protocol=udp
bind=0.0.0.0:5065

[6001]
type=endpoint
context=internal
disallow=all
allow=ulaw
auth=6001
aors=6001

[6001]
type=auth
auth_type=userpass
password=1930133
username=6001

[6001]
type=aor
max_contacts=1

Also take a look to https://wiki.asterisk.org/wiki/display/AST/Asterisk+PJSIP+Troubleshooting+Guide

401 is not an error. It is a request to provide authentication, together with information on how to do so. The peer should send the authentication data in response.

as @david551 said, 401 is not an error. It is normal stage in the registration process. If the registering device doesn’t proceed beyond the 401, it means it does not know how to authenticate itself.