Comments (9)
Thanks @mikepianka for raising this issue.
Unfortunately I am not able to reproduce this issue, and I think the problem is I do not have a windows machine with the same setup you have. It seems you have mcafee firewall installed in your machine, and it is blocking the call to https://checkip.amazonaws.com
from aws-sam-cli-app-templates.
can you try to allow list the url https://checkip.amazonaws.com
in your Mcafee
from aws-sam-cli-app-templates.
So I'm not actually running Mcafee and I did think that error was strange. I think the issue might actually just be with the https://checkip.amazonaws.com endpoint itself. It seems like its TLS cert is flakey.
I just tried again with curl, and I was able to successfully hit the endpoint, but then a few minutes later I tried again and hit an error. In Chrome, I tried visiting it and got redirected to my ISP's page with a Mcafee warning (that must be where the Mcafee message originates from). I tried refreshing in Chrome a few minutes later and it went through and showed my IP as expected.
I changed up the hello world example to use jsonplaceholder and it all works as expected.
package main
import (
"encoding/json"
"errors"
"fmt"
"io"
"net/http"
"github.com/aws/aws-lambda-go/events"
"github.com/aws/aws-lambda-go/lambda"
)
var (
// DefaultHTTPGetAddress Default Address
DefaultHTTPGetAddress = "https://jsonplaceholder.typicode.com/albums/1"
// ErrNoTitle No album title found in response
ErrNoTitle = errors.New("No album title in HTTP response")
// ErrNon200Response non 200 status code in response
ErrNon200Response = errors.New("Non 200 Response found")
)
type Album struct {
UserID int `json:"userId"`
ID int `json:"id"`
Title string `json:"title"`
}
func handler(request events.APIGatewayProxyRequest) (events.APIGatewayProxyResponse, error) {
resp, err := http.Get(DefaultHTTPGetAddress)
if err != nil {
return events.APIGatewayProxyResponse{}, err
}
if resp.StatusCode != 200 {
return events.APIGatewayProxyResponse{}, ErrNon200Response
}
content, err := io.ReadAll(resp.Body)
if err != nil {
return events.APIGatewayProxyResponse{}, err
}
var album Album
err = json.Unmarshal(content, &album)
if err != nil {
return events.APIGatewayProxyResponse{}, err
}
if len(album.Title) == 0 {
return events.APIGatewayProxyResponse{}, ErrNoTitle
}
return events.APIGatewayProxyResponse{
Body: fmt.Sprintf("Hello! Have you listened to the new album <%s>?\n", album.Title),
StatusCode: 200,
}, nil
}
func main() {
lambda.Start(handler)
}
from aws-sam-cli-app-templates.
thanks @mikepianka for the detailed explanation. As you mentioned, the problem is in https://checkip.amazonaws.com/
endpoint itself, which we could not fix. But I believe it is better to update our template to use some other endpoint or something else, as using this endpoint is not the purpose of our templates.
from aws-sam-cli-app-templates.
Sounds good. Do you want me to open a PR with my example? I could swap it out for a different endpoint if you have something else in mind.
from aws-sam-cli-app-templates.
Actually I just realized that since this example uses API Gateway proxy, you should be able to just get the caller's IP right from the identity sourceIP property on the request object. So the example could function the same but not rely on an extra web request. What do you think of that?
from aws-sam-cli-app-templates.
Actually the main purpose of this template is to show how to create a Go Lambda function with an API Gateway resource. Calling https://checkip.amazonaws.com
endpoint or any other service is not part of the template purpose. So, I think it will be better to use the Request to get this IP, but make sure that if the Lambda function got invoked directly with different event, it will not fail. Your contribution is appreciated :)
from aws-sam-cli-app-templates.
Hi @moelasmar. It took a bit of time for me to get back to this, but I made a PR to fix the examples here - #431
from aws-sam-cli-app-templates.
This has been merged in #431, resolving.
from aws-sam-cli-app-templates.
Related Issues (20)
- Hello World Example TypeScript Error: Cannot find module 'app' HOT 1
- .NET and TypeScript aren't part of Hello World Example With Powertools group HOT 3
- Bug: Java Docker Gradle templates fail (all variants) HOT 2
- Improvement: add explicit class parameter to the logger in lambda powertools project HOT 1
- Bug: Rust DynamoDB Example expands Rust Hello World Example template instead HOT 2
- Bug: SAM template title is confusing HOT 2
- Template for Hello World with Powertools doesn't exist for Python3.10 HOT 2
- Documentation: Removing `aws cloudformation delete-stack` HOT 3
- Feature request: Full stack web app HOT 2
- Improve build & test by running pytest in multithread HOT 2
- Feature request: Have a documentaton for each SAM template HOT 3
- Feature request: Python sample project containing a scheduled task event HOT 1
- Bug: .NET 6 templates does not build on SAM CLI HOT 2
- [TypeScript template] `sam local invoke` command shows the error: Cannot find module 'app' HOT 2
- Behind Firewall/Proxy - mvn Test, sam build, sam invoke failures for HelloworldFunctions HOT 3
- Optimize docker images for newer python HOT 1
- Why is esbuild a direct dependency rather than a dev dependency? HOT 2
- Bug: s3-app with node 16 - sam local invoke fails with ACCESS DENIED HOT 6
- Bug: Duplicate Use Case "Hello World Example With Powertools for AWS Lambda" HOT 2
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
D3
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
-
Recommend Topics
-
javascript
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
-
web
Some thing interesting about web. New door for the world.
-
server
A server is a program made to process requests and deliver data to clients.
-
Machine learning
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from aws-sam-cli-app-templates.