In addition to Weibo, there is also WeChat
Please pay attention
WeChat public account
Shulou
2025-01-16 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Servers >
Share
Shulou(Shulou.com)06/03 Report--
Configuration and function to write public configuration to create a proprietary network VPC to log in to the VPC console. See VPC to build a proprietary network to create VPC and switches. Create a security group
Create a new security group in the Security Group console, click create Security Group, set the security group name, select the private network for the network type, and select the private network you just created.
Create and configure Redis instances
To create an instance of Redis version of cloud database that meets business needs, please refer to Redis version of cloud database.
After the creation is successful, click whitelist Settings in the navigation bar on the left side of the instance information page.
Click modify to the right of the default area box.
In the pop-up dialog box, configure the network segment address of the VPC network where the function calculation is located in the whitelist input box.
Log in to the VPC console, find the VPC where the application is located in the list of proprietary networks, and click the name of the VPC to enter the private network details page. Copy the IPv4 network segment of the VPC where the application is located.
Paste the IPv4 segment address of the VPC in the whitelist settings box in the group, and then click OK.
Finally, access the Redis database host as the private network address of the instance, and log in to the Aliyun console to view:
Multi-language client connection Aliyun Redis can refer to Redis client connection.
Function calculates configuration VPC
Note: the area where the function calculation service is located is the same as that of the resources created in the public configuration.
Create a service in the function calculation console. For the steps to create a service, please refer to the "add, delete, modify" option of "proprietary Network configuration" in the article, and select the VPC network, switch and security group you created in step 1. In the "permission configuration" option, select "New role", click "Click Authorization", and then click "agree to Authorization" on the role Quick creation page. The operation of this step is to grant the function permission to operate on the ENI. To calculate the permissions required to access the resources in the VPC, please refer to the article configuring the function to calculate the click to access the resources in the VPC. The new service is completed. Function writing and debugging
The following demonstrates the example creation of a Python3 development language access Redis database function:
Use the Fun tool to install dependencies and project deployments under the directory where code and dependency modules are created.
Create a directory to store the code and dependency modules, and create a new template.yml file in that directory, such as / tmp/code/template.yml The content is: ROSTemplateFormatVersion: '2015-09-01'Transform:' Aliyun::Serverless-2018-04-03'Resources:Redis-test: Type: 'Aliyun::Serverless::Service' Properties: Description: This is Redis service Role:' acs:ram::XXX:role/fc-public-test' LogConfig: Project: XXX Logstore: XXXX VpcConfig: VpcId: vpc-XXXXX VSwitchIds:-vsw-XXXX SecurityGroupId : sg-XXXX InternetAccess: true python-test: Type: 'Aliyun::Serverless::Function' Properties: Initializer:' index.initializer' Handler: 'index.handler' Runtime: python3 Timeout: 10 MemorySize: 128 CodeUri:'. / 'EnvironmentVariables: REDIS_HOST: r-XXXXX.redis.rds.aliyuncs.com REDIS_PASSWORD: XXXXX REDIS_PORT:' 6379' Create a Funfile file in this directory as follows: RUNTIME python3RUN fun-install pip install redis
Execute the fun install command to install dependencies:
$fun installusing template: template.ymlstart installing function dependencies without dockerbuilding Redis-test/python-testFunfile exist Fun will use container to build forcelyStep 1 4205-a670 2: FROM registry.cn-beijing.aliyuncs.com/aliyunfc/runtime-python3.6:build-1.7.7-> 373f5819463bStep 2 24e4daf88284:latestcopying function artifact to 2: RUN fun-install pip install redis-> Running in f26aef48f9e5Task = > PipTask = > PYTHONUSERBASE=/code/.fun/python pip install-- user redisRemoving intermediate container f26aef48f9e5-- > 809c6655f9e9sha256:809c6655f9e93d137840b1446f46572fbab7548c5c36b6ae66599dfc2e27555bSuccessfully built 809c6655f9e9Successfully tagged fun-cache-78c74899-5497-4205-a670-24e4daf88284:latestcopying function artifact to / Users/txd123/Desktop/Redis/PythonInstall Success
Create a new code file under the root of the function, such as / tmp/code/index.py, and use redis in the code:
#-*-coding: utf-8-*-import os,sysimport redisdef initializer (context): global conn_pool conn_pool=redis.ConnectionPool (host=os.environ ['REDIS_HOST'], password=os.environ [' REDIS_PASSWORD'], port=os.environ ['REDIS_PORT'], db=1,decode_responses=True) def handler (event, context): r = redis.Redis (connection_pool=conn_pool) r.set (' test','89898') r.set ('zyh_info') '{"name": "Tanya", "password": "123456", "account": 11234}') print (r.get ('test')) return r.get (' zyh_info')
Deploy using the fun tool:
$fun deployusing template: template.ymlusing region: cn-hangzhouusing accountId: * 3743using accessKeyId: * Ptgkusing timeout: 60Waiting for service Redis-test to be deployed... Waiting for function python-test to be deployed... Waiting for packaging function python-test code... The function python-test has been packaged. A total of 25 files files were compressed and the final size was 138.78 KB function python-test deploy successservice Redis-test deploy success
Log in to the console to see that the relevant services and functions have been created successfully, and the correct results can be returned by triggering the execution.
Welcome to subscribe "Shulou Technology Information " to get latest news, interesting things and hot topics in the IT industry, and controls the hottest and latest Internet news, technology news and IT industry trends.
Views: 0
*The comments in the above article only represent the author's personal views and do not represent the views and positions of this website. If you have more insights, please feel free to contribute and share.
Continue with the installation of the previous hadoop.First, install zookooper1. Decompress zookoope
"Every 5-10 years, there's a rare product, a really special, very unusual product that's the most un
© 2024 shulou.com SLNews company. All rights reserved.