要解决AWS API网关无法从S3网页访问的问题,可以按照以下步骤进行操作:
import boto3
s3_client = boto3.client('s3')
response = s3_client.put_bucket_website(
Bucket='your-bucket-name',
WebsiteConfiguration={
'IndexDocument': {'Suffix': 'index.html'},
'ErrorDocument': {'Key': 'error.html'}
}
)
import boto3
api_client = boto3.client('apigateway')
response = api_client.put_integration(
restApiId='your-api-id',
resourceId='your-resource-id',
httpMethod='GET',
type='AWS_PROXY',
integrationHttpMethod='POST',
uri='arn:aws:apigateway:your-region:s3:path/your-bucket-name/{proxy}'
)
response = api_client.create_deployment(
restApiId='your-api-id',
stageName='your-stage-name'
)
response = api_client.create_resource(
restApiId='your-api-id',
parentId='your-parent-resource-id',
pathPart='your-path-part'
)
response = api_client.put_method(
restApiId='your-api-id',
resourceId='your-resource-id',
httpMethod='GET',
authorizationType='NONE'
)
response = api_client.put_method_response(
restApiId='your-api-id',
resourceId='your-resource-id',
httpMethod='GET',
statusCode='200',
responseModels={'application/json': 'Empty'}
)
response = api_client.create_deployment(
restApiId='your-api-id',
stageName='your-stage-name'
)
response = api_client.create_integration_response(
restApiId='your-api-id',
resourceId='your-resource-id',
httpMethod='GET',
statusCode='200',
responseTemplates={'application/json': ''}
)
response = api_client.create_deployment(
restApiId='your-api-id',
stageName='your-stage-name'
)
完成上述步骤后,您应该能够通过API网关访问S3存储桶中的网页。确保替换代码示例中的必要参数,例如存储桶名称、API ID、资源ID和区域等。
上一篇:AWS API 网关文件上传失败
下一篇:AWS API 网关延迟