GithubHelp home page GithubHelp logo

Comments (6)

dyingsunlight avatar dyingsunlight commented on June 27, 2024 1

Thanks, it's looks working now!

from aws-sam-cli.

hnnasit avatar hnnasit commented on June 27, 2024

Hi @dyingsunlight, thanks for reporting the issue. I tried to deploy the app and browse the URL but could not see the image. As for the isBase64Encoded: False in the debug logs, it seems this is for the input event sent to the lambda function. I think what you are looking for is the response to return True for isBase64Encoded and looking at this code, the boolean value is a string. Can you check if setting it to a string works?

from aws-sam-cli.

dyingsunlight avatar dyingsunlight commented on June 27, 2024

It's not working... I tried setting isBase64Encoded to 'true' and 'True', but the debug message still outputs: 'isBase64Encoded': False.

The debug logs:

Constructed Event 1.0 to invoke Lambda. Event: {'version': '1.0', 'httpMethod': 'GET', 'body': None, 'resource': '/hello-world', 'requestContext': {'resourceId': '123456', 'apiId': '1234567890',        
'resourcePath': '/hello-world', 'httpMethod': 'GET', 'requestId': '35b543fb-3f9b-4ba4-80a0-c1983c882814', 'accountId': '123456789012', 'stage': 'Prod', 'identity': {'apiKey': None, 'userArn': None, 'cognitoAuthenticationType':  
None, 'caller': None, 'userAgent': 'Custom User Agent String', 'user': None, 'cognitoIdentityPoolId': None, 'cognitoAuthenticationProvider': None, 'sourceIp': '127.0.0.1', 'accountId': None}, 'extendedRequestId': None, 'path':  
'/hello-world', 'protocol': 'HTTP/1.1', 'domainName': '127.0.0.1:8090', 'requestTimeEpoch': 1702792298, 'requestTime': '17/Dec/2023:05:51:38 +0000'}, 'queryStringParameters': None, 'multiValueQueryStringParameters': None,       
'headers': {'Host': '127.0.0.1:8090', 'Connection': 'keep-alive', 'Cache-Control': 'max-age=0', 'Sec-Ch-Ua': '"Not_A Brand";v="8", "Chromium";v="120", "Google Chrome";v="120"', 'Sec-Ch-Ua-Mobile': '?0', 'Sec-Ch-Ua-Platform':    
'"Windows"', 'Upgrade-Insecure-Requests': '1', 'User-Agent': 'Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/120.0.0.0 Safari/537.36', 'Accept':
'text/html,application/xhtml+xml,application/xml;q=0.9,image/avif,image/webp,image/apng,*/*;q=0.8,application/signed-exchange;v=b3;q=0.7', 'Sec-Fetch-Site': 'none', 'Sec-Fetch-Mode': 'navigate', 'Sec-Fetch-User': '?1',
'Sec-Fetch-Dest': 'document', 'Accept-Encoding': 'gzip, deflate, br', 'Accept-Language': 'zh-CN,zh;q=0.9,zh-TW;q=0.8,en;q=0.7,ja;q=0.6,ru;q=0.5', 'X-Forwarded-Proto': 'http', 'X-Forwarded-Port': '8090'}, 'multiValueHeaders':    
{'Host': ['127.0.0.1:8090'], 'Connection': ['keep-alive'], 'Cache-Control': ['max-age=0'], 'Sec-Ch-Ua': ['"Not_A Brand";v="8", "Chromium";v="120", "Google Chrome";v="120"'], 'Sec-Ch-Ua-Mobile': ['?0'], 'Sec-Ch-Ua-Platform':     
['"Windows"'], 'Upgrade-Insecure-Requests': ['1'], 'User-Agent': ['Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/120.0.0.0 Safari/537.36'], 'Accept':
['text/html,application/xhtml+xml,application/xml;q=0.9,image/avif,image/webp,image/apng,*/*;q=0.8,application/signed-exchange;v=b3;q=0.7'], 'Sec-Fetch-Site': ['none'], 'Sec-Fetch-Mode': ['navigate'], 'Sec-Fetch-User': ['?1'],  
'Sec-Fetch-Dest': ['document'], 'Accept-Encoding': ['gzip, deflate, br'], 'Accept-Language': ['zh-CN,zh;q=0.9,zh-TW;q=0.8,en;q=0.7,ja;q=0.6,ru;q=0.5'], 'X-Forwarded-Proto': ['http'], 'X-Forwarded-Port': ['8090']},
'pathParameters': None, 'stageVariables': None, 'path': '/hello-world', 'isBase64Encoded': False}

I believe the issue is that, according to the documentation, the 'isBase64Encoded' value should be a boolean type, not a string type.

https://docs.aws.amazon.com/apigateway/latest/developerguide/http-api-develop-integrations-lambda.html#http-api-develop-integrations-lambda.response

from aws-sam-cli.

hnnasit avatar hnnasit commented on June 27, 2024

Marking this as a bug for the team to investigate the right behavior here.

from aws-sam-cli.

sidhujus avatar sidhujus commented on June 27, 2024

Hi, It looks like because in the template provided the api definition does not have anything declared for the BinaryMediaTypes property SAM CLI does not try to decode the image. Changing the template to the following fixed the issue for me

{
  "AWSTemplateFormatVersion": "2010-09-09",
  "Transform": "AWS::Serverless-2016-10-31",
  "Description": "",
  "Resources": {
    "HelloWorld": {
      "Type": "AWS::Serverless::Function",
      "Properties": {
        "CodeUri": "./lambda",
        "Handler": "hello-word.handler",
        "Runtime": "nodejs18.x",
        "Events": {
          "HelloWorldEvent0": {
            "Type": "Api",
            "Properties": {
              "Path": "/hello-world",
              "Method": "get",
              "RestApiId": {
                "Ref": "HelloWorldApi"
              }
            }
          }
        },
        "Timeout": 60,
        "MemorySize": 1024
      }
    },
    "HelloWorldApi": {
    "Type": "AWS::Serverless::Api",
    "Properties": {
      "StageName": "prod",
      "BinaryMediaTypes": ["image/png"]
    }
  }
  }
}

Alternatively changing the event type to HttpApi will also cause the image to be decoded. It looks like the behaviour for decoding base64 images is defined here

from aws-sam-cli.

github-actions avatar github-actions commented on June 27, 2024

⚠️COMMENT VISIBILITY WARNING⚠️

Comments on closed issues are hard for our team to see.
If you need more assistance, please either tag a team member or open a new issue that references this one.
If you wish to keep having a conversation with other community members under this issue feel free to do so.

from aws-sam-cli.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo 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.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.